Проверката за попълнени полета дава грешка

C++ JAVA
Post Reply
User avatar
Foxy
Потребител
Потребител
Posts: 1404
Joined: Mon Aug 27, 2007 6:35 am
Answers: 25
Location: Web-Tourist - Dobrich

Проверката за попълнени полета дава грешка

Post by Foxy » Sat Jul 04, 2009 8:58 pm

Здравейте! Ето го кода:

Code: Select all

<?php
session_start&#40;&#41;;
include "config.php";
$username = $_SESSION&#91;'username'&#93;;
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<?php

/**
 * @author carbonated
 * @copyright 2009
 */

if&#40;$username&#41;
&#123;
	if&#40;$_POST&#91;'submit'&#93;&#41;
	&#123;
		if&#40;$zaglavie == NULL || $text == NULL&#41;
		&#123;
			echo "<center><b>Моля попълнете всички полета!</b></center>";
		&#125;
		else
		&#123;
			$zaglavie = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'zaglavie'&#93;&#41;&#41;&#41;;
			$text = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'text'&#93;&#41;&#41;&#41;;
			$avtor = $_SESSION&#91;'username'&#93;;
			$date = date&#40;"m.d.y"&#41;;
			$sql = "INSERT INTO statii &#40;zaglavie, text, avtor, data&#41; VALUES &#40;'$zaglavie', '$text', '$avtor', '$date'&#41;";
			$result = mysql_query&#40;$sql&#41; or die &#40;mysql_error&#40;&#41;&#41;;
			echo "<center><b>Статията беше добавена успешно!</b></center>";
		&#125;
	&#125;
	else
	&#123;
		echo '
		<center><form method="post" action="addstatiq.php" style="width&#58; 800px; height&#58; 600px; border&#58; 0px solid; padding&#58; 5px;">
	  	<fieldset style="border&#58; 1px solid #000000;">
	  	<legend style="color&#58; #000000; background&#58; #ffffff; border&#58; 1px solid #000000; padding&#58; 2px 6px;">Добави статия</legend><br />
      	Заглавие&#58; <input type="text" name="zaglavie" style="width&#58; 600px; border&#58; solid 1px #000000;" /><br />
      	Текст&#58; <textarea name="text" rows="30" cols="30" style="width&#58; 600px; height&#58; 500px; margin-top&#58; 15px; margin-left&#58; 24px; border&#58; solid 1px #000000;"></textarea><br />
      	<input type="submit" name="submit" value="Добави статия" style="margin-top&#58; 5px; width&#58; 145px;" />
      	</fieldset>
	  	</form></center>';
	&#125;
&#125;
else
&#123;
	echo "<center><b>Не сте логнат! Ако се опитвате да шмекерувате всичко се записва в лог-а =&#41; !!!</b> <br />";
&#125;

?>
Почти във всяка страница ползвам проверка за попълнено поле , но в тази нещо ударих на камък - ето това е проверката:

Code: Select all

if&#40;$zaglavie == NULL || $text == NULL&#41;
Проблемът е следният - когато са попълнени полетата ми изписва, че не са попълнени и така не може да изпълни заявката, а когато махна проверката всичко си се записва в базата дании перфектно. Немога да разбера къде греша, че ми изкарва, че не съм попълнил полетата. Ако някой ми помогне +1 .

sianbg_s
Турист
Турист
Posts: 455
Joined: Tue Apr 14, 2009 7:52 pm
Answers: 20

Post by sianbg_s » Sat Jul 04, 2009 8:58 pm

Code: Select all

if&#40;&#40;$zaglavie == NULL&#41; || &#40;$text == NULL&#41;&#41;
?

User avatar
Foxy
Потребител
Потребител
Posts: 1404
Joined: Mon Aug 27, 2007 6:35 am
Answers: 25
Location: Web-Tourist - Dobrich

Post by Foxy » Sat Jul 04, 2009 9:00 pm

sianbg_s wrote:

Code: Select all

if&#40;&#40;$zaglavie == NULL&#41; || &#40;$text == NULL&#41;&#41;
?

Същата работа - (то няма разлика)

Pr0oF
Турист
Турист
Posts: 565
Joined: Sat Jun 10, 2006 8:48 pm
Answers: 38

Post by Pr0oF » Sat Jul 04, 2009 9:53 pm

Замени го с

Code: Select all

if&#40;empty&#40;$_POST&#91;'zaglavie'&#93;&#41; || empty&#40;$_POST&#91;'text'&#93;&#41;&#41;

Lenin
Турист
Турист
Posts: 236
Joined: Sat Oct 13, 2007 3:43 pm

Post by Lenin » Sun Jul 05, 2009 6:31 am

Ама, че сте... така му давате ако и двете са празни...
Трябва да стане с OR, защото ако едното е празно или другото е празно да го изписва, а не само когато и двете са празни....
Ето ти бачкащ код

Code: Select all


<?php
session_start&#40;&#41;;
include "config.php";
$username = $_SESSION&#91;'username'&#93;;
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<?php

/**
 * @author carbonated
 * @copyright 2009
 */
if&#40;$username&#41;&#123; 

   if&#40;isset&#40;$_POST&#91;'submit'&#93;&#41;&#41;
   &#123;
      if&#40;$zaglavie == NULL or $text == NULL&#41;
      &#123;
         echo "<center><b>Моля попълнете всички полета!</b></center>";
      &#125;
      else
      &#123;
	echo "done<br><br><br>$zaglavie<br><br>$text";
	
         $zaglavie = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'zaglavie'&#93;&#41;&#41;&#41;;
         $text = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'text'&#93;&#41;&#41;&#41;;
         $avtor = $_SESSION&#91;'username'&#93;;
         $date = date&#40;"m.d.y"&#41;;
         $sql = "INSERT INTO statii &#40;zaglavie, text, avtor, data&#41; VALUES &#40;'$zaglavie', '$text', '$avtor', '$date'&#41;";
         $result = mysql_query&#40;$sql&#41; or die &#40;mysql_error&#40;&#41;&#41;;
         echo "<center><b>Статията беше добавена успешно!</b></center>";  
      &#125;
   &#125;
   else
   &#123;
      echo '
      <center><form method="post" action="" style="width&#58; 800px; height&#58; 600px; border&#58; 0px solid; padding&#58; 5px;">
        <fieldset style="border&#58; 1px solid #000000;">
        <legend style="color&#58; #000000; background&#58; #ffffff; border&#58; 1px solid #000000; padding&#58; 2px 6px;">Добави статия</legend><br />
         Заглавие&#58; <input type="text" name="zaglavie" style="width&#58; 600px; border&#58; solid 1px #000000;" /><br />
         Текст&#58; <textarea name="text" rows="30" cols="30" style="width&#58; 600px; height&#58; 500px; margin-top&#58; 15px; margin-left&#58; 24px; border&#58; solid 1px #000000;"></textarea><br />
         <input type="submit" name="submit" value="Добави статия" style="margin-top&#58; 5px; width&#58; 145px;" />
         </fieldset>
        </form></center>';
   
   &#125;&#125;
else
&#123;
   echo "<center><b>Не сте логнат! Ако се опитвате да шмекерувате всичко се записва в лог-а =&#41; !!!</b> <br />";
&#125;


?>

:?: :?:

User avatar
Foxy
Потребител
Потребител
Posts: 1404
Joined: Mon Aug 27, 2007 6:35 am
Answers: 25
Location: Web-Tourist - Dobrich

Post by Foxy » Sun Jul 05, 2009 10:18 am

Отново ми изписва моля попълнете всички полета :(

User avatar
devent
Web-tourist
Web-tourist
Posts: 2542
Joined: Wed Sep 06, 2006 10:21 pm
Answers: 399

Post by devent » Sun Jul 05, 2009 10:20 am

Code: Select all

<?php
session_start&#40;&#41;;
include "config.php";
$username = $_SESSION&#91;'username'&#93;;
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<?php

/**
 * @author carbonated
 * @copyright 2009
 */

if&#40;$username&#41;
&#123;
   if&#40;$_POST&#91;'submit'&#93;&#41;
   &#123;
      $zaglavie = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'zaglavie'&#93;&#41;&#41;&#41;;
      $text = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'text'&#93;&#41;&#41;&#41;;
      if&#40;$zaglavie == NULL || $text == NULL&#41;
      &#123;
         echo "<center><b>Моля попълнете всички полета!</b></center>";
      &#125;
      else
      &#123;
         $avtor = $_SESSION&#91;'username'&#93;;
         $date = date&#40;"m.d.y"&#41;;
         $sql = "INSERT INTO statii &#40;zaglavie, text, avtor, data&#41; VALUES &#40;'$zaglavie', '$text', '$avtor', '$date'&#41;";
         $result = mysql_query&#40;$sql&#41; or die &#40;mysql_error&#40;&#41;&#41;;
         echo "<center><b>Статията беше добавена успешно!</b></center>";
      &#125;
   &#125;
   else
   &#123;
      echo '
      <center><form method="post" action="addstatiq.php" style="width&#58; 800px; height&#58; 600px; border&#58; 0px solid; padding&#58; 5px;">
        <fieldset style="border&#58; 1px solid #000000;">
        <legend style="color&#58; #000000; background&#58; #ffffff; border&#58; 1px solid #000000; padding&#58; 2px 6px;">Добави статия</legend><br />
         Заглавие&#58; <input type="text" name="zaglavie" style="width&#58; 600px; border&#58; solid 1px #000000;" /><br />
         Текст&#58; <textarea name="text" rows="30" cols="30" style="width&#58; 600px; height&#58; 500px; margin-top&#58; 15px; margin-left&#58; 24px; border&#58; solid 1px #000000;"></textarea><br />
         <input type="submit" name="submit" value="Добави статия" style="margin-top&#58; 5px; width&#58; 145px;" />
         </fieldset>
        </form></center>';
   &#125;
&#125;
else
&#123;
   echo "<center><b>Не сте логнат! Ако се опитвате да шмекерувате всичко се записва в лог-а =&#41; !!!</b> <br />";
&#125;

?>

Lenin
Турист
Турист
Posts: 236
Joined: Sat Oct 13, 2007 3:43 pm

Post by Lenin » Sun Jul 05, 2009 10:58 am

Foxy wrote:Отново ми изписва моля попълнете всички полета :(

Абе момче, някъде другаде ти е грешката, пробвах го кода на локалния хост и си баца перфектно :o

User avatar
Foxy
Потребител
Потребител
Posts: 1404
Joined: Mon Aug 27, 2007 6:35 am
Answers: 25
Location: Web-Tourist - Dobrich

Post by Foxy » Sun Jul 05, 2009 11:06 am

devent wrote:

Code: Select all

<?php
session_start&#40;&#41;;
include "config.php";
$username = $_SESSION&#91;'username'&#93;;
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<?php

/**
 * @author carbonated
 * @copyright 2009
 */

if&#40;$username&#41;
&#123;
   if&#40;$_POST&#91;'submit'&#93;&#41;
   &#123;
      $zaglavie = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'zaglavie'&#93;&#41;&#41;&#41;;
      $text = trim&#40;htmlspecialchars&#40;addslashes&#40;$_POST&#91;'text'&#93;&#41;&#41;&#41;;
      if&#40;$zaglavie == NULL || $text == NULL&#41;
      &#123;
         echo "<center><b>Моля попълнете всички полета!</b></center>";
      &#125;
      else
      &#123;
         $avtor = $_SESSION&#91;'username'&#93;;
         $date = date&#40;"m.d.y"&#41;;
         $sql = "INSERT INTO statii &#40;zaglavie, text, avtor, data&#41; VALUES &#40;'$zaglavie', '$text', '$avtor', '$date'&#41;";
         $result = mysql_query&#40;$sql&#41; or die &#40;mysql_error&#40;&#41;&#41;;
         echo "<center><b>Статията беше добавена успешно!</b></center>";
      &#125;
   &#125;
   else
   &#123;
      echo '
      <center><form method="post" action="addstatiq.php" style="width&#58; 800px; height&#58; 600px; border&#58; 0px solid; padding&#58; 5px;">
        <fieldset style="border&#58; 1px solid #000000;">
        <legend style="color&#58; #000000; background&#58; #ffffff; border&#58; 1px solid #000000; padding&#58; 2px 6px;">Добави статия</legend><br />
         Заглавие&#58; <input type="text" name="zaglavie" style="width&#58; 600px; border&#58; solid 1px #000000;" /><br />
         Текст&#58; <textarea name="text" rows="30" cols="30" style="width&#58; 600px; height&#58; 500px; margin-top&#58; 15px; margin-left&#58; 24px; border&#58; solid 1px #000000;"></textarea><br />
         <input type="submit" name="submit" value="Добави статия" style="margin-top&#58; 5px; width&#58; 145px;" />
         </fieldset>
        </form></center>';
   &#125;
&#125;
else
&#123;
   echo "<center><b>Не сте логнат! Ако се опитвате да шмекерувате всичко се записва в лог-а =&#41; !!!</b> <br />";
&#125;

?>


Мерси @devent - стана +1

User avatar
devent
Web-tourist
Web-tourist
Posts: 2542
Joined: Wed Sep 06, 2006 10:21 pm
Answers: 399

Post by devent » Sun Jul 05, 2009 11:20 am

Разбра ли си грешката? :)

Post Reply