part of form.php
add.phpHTML Code:<form action="add.php" method="post"> <table bgcolor="#EFEFEF" border="1" align="center" cellpadding="1" cellspacing="1"> <tr> <td height="23" colspan="2" bgcolor="#DDEEFF"><div align="center">Category</div></td> </tr> <tr> <td height="62"><div align="center"><strong><font color="#800040" face="Verdana">Name of the category::</font></strong></div></td> <td><strong><font color="#000000" face="Verdana"> <input name="category[]" type="text" id="category" value=""> </font></strong> <p> <span id="catAttachments"></span><strong> <a href="javascript:catAttachment(); void(0);"><font color="#000000" face="Verdana">(Add More Categories)</font></a><br /> <font size="-1">Maximum more allowed : 4</font> </strong></td> </tr> <tr> <td height="41" colspan="2"> <div align="center"> <strong> <input type="submit" name="button" value="Add Category"> </strong></div></td> </tr>
the problem is in add.php the else part is not being executedPHP Code:<?php if($_REQUEST['button']=="Add Category"){
if(!empty($_REQUEST['category'])){
foreach($_REQUEST['category'] as $category){
$sql=mysql_query("INSERT INTO category(`category`) VALUE('".addslashes($category)."')");
if($sql)
echo "Category ".$category." created";
echo "<br/>";}?>
<a href="index.php">Back</a><?php
exit();
}
else
{
echo "You need to enter the name of the category";?>
<a href="index.php">Back</a><?php
exit();
}
}
even if i do not enter anything in the form
it creates a category with name ""






Bookmarks