Jump to content

Why won't my records delete?


poleposters

Recommended Posts

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

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

<?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'")

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.