Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-03-2007, 06:39 PM   PM User | #1
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
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
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 06-03-2007, 06:41 PM   PM User | #2
twomt
New Coder

 
Join Date: Sep 2006
Posts: 92
Thanks: 4
Thanked 1 Time in 1 Post
twomt is an unknown quantity at this point
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 06:45 PM..
twomt is offline   Reply With Quote
Old 06-03-2007, 07:05 PM   PM User | #3
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
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
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 06-03-2007, 07:20 PM   PM User | #4
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
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']}"
mr e is offline   Reply With Quote
Old 06-03-2007, 07:45 PM   PM User | #5
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
removed the single quotes and still getting error
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 06-03-2007, 08:42 PM   PM User | #6
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
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
mr e is offline   Reply With Quote
Old 06-03-2007, 08:55 PM   PM User | #7
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
still showing me the same error with die(mysql_query())
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 06-03-2007, 09:00 PM   PM User | #8
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
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?
mr e is offline   Reply With Quote
Old 06-03-2007, 09:13 PM   PM User | #9
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
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
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 06-03-2007, 09:16 PM   PM User | #10
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
Missing a comma
PHP Code:
$sql .= ", `dob` = '$dob' WHERE userid = {$_SESSION['userid']}"
PappaJohn is offline   Reply With Quote
Old 06-03-2007, 09:21 PM   PM User | #11
mr e
Regular Coder

 
Join Date: Apr 2007
Posts: 295
Thanks: 0
Thanked 19 Times in 19 Posts
mr e is on a distinguished road
Now what you need to do is make sure there isn't a comma there if $updateArray is empty, or it'll break again
mr e is offline   Reply With Quote
Old 06-03-2007, 09:26 PM   PM User | #12
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
rep added accordingly
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 06-03-2007, 10:36 PM   PM User | #13
twomt
New Coder

 
Join Date: Sep 2006
Posts: 92
Thanks: 4
Thanked 1 Time in 1 Post
twomt is an unknown quantity at this point
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 05:48 AM..
twomt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:34 AM.


Advertisement
Log in to turn off these ads.