Hi forum,
I am having a problem with form in php........making an add and delete categories button in my form......................this is how I am doing it.
PHP Code:
<form name="category" id="category" method="POST" action="controller/business.controller.php"> <div class="divaddbiz"> <table width=""> <tr> <td width="199"><select name="cat[]" id="cat" multiple="multiple" size="10" style="width: 200px;"> <?php $bcat_sql="select * from tblcat LIMIT 100"; $result_bcat=mysql_query($bcat_sql); while($row_bcat=mysql_fetch_array($result_bcat)) { ?> <option value="<?=$row_bcat['category_id']?>" selected="selected"> <?=$row_bcat['category']?> </option> <?php } ?> </select></td> <td width=""><table align="center" cellpadding="0" cellspacing="0"> <tr> <td width="20"></td> </tr> <tr> <td><table width="64" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td width="6"><img src="img/btm-lt.jpg" width="7" height="28" alt="" /></td> <td width="52" align="center" valign="middle"> <input name="insert" type="image" src="img/star-active.png" class="btm" value="Insert" /><input type="hidden" name="work" value="insertcat"> </td> <td width="6" align="left"><img src="img/btm-rt.jpg" width="7" height="28" alt="" /></td> </tr> </table></td> </tr> <tr> <td height="10"></td> </tr> <tr> <td><table width="64" border="0" align="left" cellpadding="0" cellspacing="0"> <tr> <td width="6"><img src="img/btm-lt.jpg" width="7" height="28" alt="" /></td> <td width="52" align="center" valign="middle"> <input type="image" src="img/del.png" alt="delete" border="0" /><input type="hidden" name="work" value="deleteall"></a> </td> <td width="6" align="left"><img src="img/btm-rt.jpg" width="7" height="28" alt="" /></td> </tr> </table></td> </tr> </table></td> <td width=""><select name="cat2[]" id="cat2" multiple="multiple" size="10" style="width: 200px;"> <?php $bizcat_sql="select * from tbltestbcc join tblcat t on tbltestbcc.cat_id = t.category_id where tbltestbcc.biz_id = '".$_GET['id']."' order by t.category asc"; $result_bizcat=mysql_query($bizcat_sql); while($row_bizcat=mysql_fetch_array($result_bizcat)) { ?> <option value="<?=$row_bizcat['category_id']?>"> <?=$row_bizcat['category']?> </option> <?php } ?> </select> </td> </tr> </table> </div> </form>
At the time of adding its working fine but when I goes to "Delete image" Its still stuck with the adding option...........sometime it works fine with delete and sometime with add.......both are not working accurately....
This is how I am controlling it..
PHP Code:
if($_POST['work']=="insertcat") {
$business = new business;
if(!empty($_POST['cat'])) { $biz = $_POST['bizval_f']; $biz_city = $_POST['city_cat']; $cityname = $_POST['cityname']; for($i=0; $i<sizeof($_POST['cat']); $i++) { $result = $business->bcc_add($_POST['cat'][$i],$biz_city,$_POST['bizval_f']); //$list1[$i] = $_POST['cat'][$i]; } if($result) { $_SESSION["msg"] = "Categories added successfully."; $url = "../add_biz.php?id=".$biz."&city=".$cityname;
header("Location: $url"); die;
} else { //$coupon->setsession($set); $_SESSION["msg"] = "Error! unable to add subcategories."; //header("Location: ../add_coupon.php"); print("<script language='javascript'>location.href='../add_coupon.php'</script>"); die; }
} }
if($_POST['work']=="deleteall") {
$business = new business;
if(!empty($_POST['cat2'])) { $biz = $_POST['bizval_f']; $biz_city = $_POST['city_cat']; for($i=0; $i<sizeof($_POST['cat2']); $i++) { $result = $business->bcc_delete($_POST['cat2'][$i],$_POST['bizval_f'],$biz_city); //$list1[$i] = $_POST['cat'][$i]; } if($result) { $_SESSION["msg"] = "Subcategories Deleted successfully."; $url = "../add_biz.php?id=".$biz."&city=".$cityname;
header("Location: $url"); die;
} else { //$coupon->setsession($set); $_SESSION["msg"] = "Error! unable to Delete subcategories."; //header("Location: ../add_coupon.php"); print("<script language='javascript'>location.href='../add_biz.php'</script>"); die; }
} } else { $_SESSION["msg"] = "Error! work condition doesn't match."; $url = "../add_biz.php?id=".$biz."&city=".$cityname;
header("Location: $url"); die; }
Please let me know where I mistook.....thanks for your help.
Last edited by Isabella_Smith; 04-08-2010 at 10:43 AM..
|