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 13 of 13
  1. #1
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts

    mysql update error

    Code:
    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 'dob=`''1969-12-31'' WHERE userid = 5' at line 1
    php code ==
    PHP Code:
    $sql .= "`dob =`'$dob' WHERE userid = {$_SESSION['userid']}"
    its worth rep for the first correct solution

  2. #2
    New Coder
    Join Date
    Sep 2006
    Posts
    92
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by rafiki View Post
    Code:
    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 'dob=`''1969-12-31'' WHERE userid = 5' at line 1
    php code ==
    PHP Code:
    $sql .= "`dob =`'$dob' WHERE userid = {$_SESSION['userid']}"
    its worth rep for the first correct solution

    $sql .= "SET `dob` = '$dob' WHERE `userid` = {$_SESSION['userid']}";

    might be me, but I would have the quote before the = and not after
    Last edited by twomt; 06-03-2007 at 07:45 PM.

  3. #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    no i have the same error
    Code:
    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 'dob` = ''1969-12-31'' WHERE userid = 5' at line 1
    PHP Code:
    $sql "UPDATE users set ";
    foreach(
    $_POST as $key=>$val)
    {
      if(
    in_array($key$validFields)) 
      {
        
    $updateArray[] =$key = ".sqlProtect($val);
      }
    }
    $dob sqlProtect($dob);
    $sql .= implode(", "$updateArray); 
    $sql .= "`dob` = '$dob' WHERE userid = {$_SESSION['userid']}";
    $result mysql_query($sql); 
    is the whole query

  4. #4
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    It looks like $dob is a string that's already surrounded by single quotes, so surrounding it again is giving you an error, I would try removing the single quotes around it in your query
    PHP Code:
    $sql .= "`dob` = $dob WHERE userid = {$_SESSION['userid']}"

  5. #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    removed the single quotes and still getting error

  6. #6
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    Change $result = mysql_query($sql); to $result = mysql_query($sql) or die(mysql_error()); and show us what the actual query looks like, I bet it has something to do with the array you're imploding

  7. #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    still showing me the same error with die(mysql_query())

  8. #8
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    Ah duh sorry, this is what I meant to post
    PHP Code:
    $result mysql_query($sql) or die(mysql_error() ."\n"$sql); 
    What's it say $sql is?

  9. #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Code:
    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 'dob` = '1969-12-31' WHERE userid = 5' at line 1 UPDATE users set education = 'highschool16', employment = 'unemployed', ms = 'single', children = '0', income = '<10'`dob` = '1969-12-31' WHERE userid = 5
    thats what it says

  10. #10
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Missing a comma
    PHP Code:
    $sql .= ", `dob` = '$dob' WHERE userid = {$_SESSION['userid']}"

  11. #11
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    Now what you need to do is make sure there isn't a comma there if $updateArray is empty, or it'll break again

  12. #12
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    rep added accordingly

  13. #13
    New Coder
    Join Date
    Sep 2006
    Posts
    92
    Thanks
    4
    Thanked 1 Time in 1 Post
    PHP Code:
    function updateUsers$userID$updateArray ) {

        
    $sql "update users set ";

        foreach( 
    $updateArray as $column=>$value ) {
            
    $value addslashes($value);

            if ( 
    is_string($value) && (strlen($value) > 1) && ($value[0] == "@") ) {
                
    $updateSQL[] = "$column="substr($value1);
            } else {
                
    $updateSQL[] = "$column='$value'";
            }
        }

        
    $sql.= implode(", "$updateSQL) . " where userid=$userID";
        return 
    mysql_query($sql);

    Now you can call this as follows:

    PHP Code:
    updateUsers( {$_SESSION['userid']}, "dob"=>"$dob); 
    should work.....
    Last edited by twomt; 06-04-2007 at 06:48 AM.


 

Posting Permissions

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