...

View Full Version : Resolved insert after delete not working



harkly
11-14-2011, 10:39 PM
Having an issue with removing data from a table and inserting into another.

I am checking a table to see if a user exist, if they do then I want to remove that user from the table and insert the info into another table.

What is working is the checking and the removal, but am getting this error and it is not inputting the info into the 2nd table


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1


if ($id == "block") {

//checking to see that user is not in the saved, if it is removing it
$result2=mysql_query("SELECT * FROM saveUser WHERE userID='$clientID' AND saveID='$userID'");
$num_rows = mysql_num_rows($result2);

// deleting from table
if ($num_rows >= 1 ) {
$query1=mysql_query("DELETE FROM saveUser WHERE userID='$clientID' AND saveID='$userID'");
$result = mysql_query($query1) or die(mysql_error());
}

// now inserting info to block the user from appearing
$query2 = ("INSERT INTO blockUser VALUES(NULL,'$clientID','$userID')");
$result = mysql_query($query2) or die(mysql_error());
}


Code works fine if the user has not been saved before hand. Can someone see where my issue is?

Old Pedant
11-14-2011, 11:55 PM
Ready to kick yourself?


$query1=mysql_query("DELETE FROM saveUser WHERE userID='$clientID' AND saveID='$userID'");
$result = mysql_query($query1) or die(mysql_error());

You are trying to run mysql_query on the *RESULT* of the already-executed mysql_query.

After the first line there, $query1 will hold either null or some kind of success value. Looks like it must hold "1".

So of course when you try to run a sql query on the string "1" MySQL just shakes its head.

** NOW ** try


$query1="DELETE FROM saveUser WHERE userID='$clientID' AND saveID='$userID'";
$result = mysql_query($query1) or die(mysql_error());

harkly
11-15-2011, 04:10 PM
Thanks!

Kicking myself right now!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum