Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts

    insert after delete not working

    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
    PHP Code:
    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 >= ) {
                
    $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?
    Last edited by harkly; 11-15-2011 at 04:10 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Ready to kick yourself?
    Code:
                $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
    Code:
                $query1="DELETE FROM saveUser WHERE userID='$clientID' AND saveID='$userID'";
                $result = mysql_query($query1) or die(mysql_error());
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    harkly (11-15-2011)

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Thanks!

    Kicking myself right now!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •