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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    why is this query failing?

    Greetings,

    Can someone please tell me why the following query is failing?

    Code:
    		$qryupdate = "INSERT INTO Warranty (servicetag, description, provider, startdate, enddate, daysleft) " .
    				"VALUES ('$servicetag', '$description', '$provider', '$startdate', '$enddate', '$daysleft') " .
    				"WHERE (servicetag='$servicetag', description='$description', provider='$provider', " .
    				"startdate='$startdate', enddate='$enddate')";
    
    		$results = mysql_query($qryupdate);
    Thanks,

    *Nick*

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You can't have a where clause on an insert statement. Use update if that's what you need to do.

    Good luck;

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to replace the old values with the new values. UPDATE doesn't work because if the old values are the same as the new values it fails, which is fine, but the way the rest of my code is designed:

    Code:
    if (mysql_affected_rows() == -1)
    {
    
    $qryinsert = "INSERT INTO Warranty (servicetag, description, provider, startdate, enddate, daysleft) " .
    "VALUES ('$servicetag', '$description', '$provider', '$startdate', '$enddate', '$daysleft') ";
    
    $results = mysql_query($qryinsert);
    
    }
    ...so the information is just inserted into the table instead of being overwritten/updated. Make sense?
    INSERTing is fine if the information doesn't already exist in the table. But if the information already does exist in the table, I want to update it because, more then likely, the information in $daysleft will change daily.

    Thanks,

    *Nick*

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    See the manual for insert on duplicate update that is what you should use.


  •  

    Posting Permissions

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