poleposters Posted September 30, 2008 Share Posted September 30, 2008 Hi, I have a piece of code that dynamically prints a series of checkboxes. So that the records aren't recorded multiple times, I have a delete query before new records are added. But its not working! Can anyone see what I'm doing wrong. I'm not getting an error. The records just pile up every time I submit the form. <?php if(isset($_POST['submit'])) { $kink=$_POST["fields"]; $bid=$_SESSION['business_id']; $n=count($kink); echo "User chose $n items from the list.<br>\n"; $delete="DELETE FROM specialties WHERE business_id=1"; $clear=mysql_query($delete) or trigger_error("Query: $delete\n<br />MySQL Error: " . mysql_error()); for($i=0;$i<$n;$i++) { $query="INSERT INTO specialties (specialty_id,business_id,specialty) VALUES ('','1','$kink[$i]')"; $result=mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); } } else { print" <form id=\"specialties\" action=\"specialties.php\" method=\"post\"> <fieldset class=\"specialties\">"; $bid=$_SESSION['business_id']; $query4="SELECT * FROM specialtytype"; $check=mysql_query($query4); $n=mysql_num_rows($check); if($n>0){ while($check2=mysql_fetch_assoc($check)){ $cat_id=$check2['category_id']; $cat=$check2['category']; print" <label for=\"$cat\">$cat</label> <input type=\"checkbox\" name=\"fields[]\" value=\"$cat_id\""; print ">"; } } print" <input type=\"submit\" class=\"continue\" name=\"submit\" value=\" \" /> </form> "; } ?> Link to comment https://forums.phpfreaks.com/topic/126408-why-wont-my-records-delete/ Share on other sites More sharing options...
jesushax Posted September 30, 2008 Share Posted September 30, 2008 well this line $clear=mysql_query($delete) or trigger_error("Query: $delete\n<br />MySQL Error: " . mysql_error()); you have declared the $delete query inside a variblae $clear and you havent used that variable anywhere i can see in the page try removing the $clear= part and see if it works Link to comment https://forums.phpfreaks.com/topic/126408-why-wont-my-records-delete/#findComment-653677 Share on other sites More sharing options...
Jibberish Posted September 30, 2008 Share Posted September 30, 2008 <?php $delete="DELETE FROM specialties WHERE business_id=1" ?> try running the delete query in phpmyadmin or whatever interface you have for mysql/oracle etc to see if the query runs (so you know if its the php thats wrong or the SQL, normally the first thing i check). I dont know much about SQL realy but it could be sumthing as simple as needing ' ' around the 1 (so the end looks like this for example ='1'") Link to comment https://forums.phpfreaks.com/topic/126408-why-wont-my-records-delete/#findComment-653685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.