Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql UPDATE error

Status
Not open for further replies.

arm207

Programmer
Jun 13, 2006
26
US
hi,
the following results in "Invalid SQL syntax error".
I tried a few different options but none seemed to have worked. Would someone please help. I believe the error is around/after the WHERE statement.

$query = "UPDATE ATAMA_users SET ".
"user_name = \"" . $formVars["username"] . "\", " .
"user_passwd = \"" . $formVars["loginPassword"] . "\", " .
"user_firstname = \"" . $formVars["firstname"] . "\", " .
"user_lastname = \"" . $formVars["lastname"] . "\", " .
"user_email = \"" . $formVars["email"] . "\", " .
"user_phone = \"" . $formVars["phone"] . "\" .
" WHERE user_id = " . $userID . "\"" ;
 
Here you go
Code:
$query = "UPDATE ATAMA_users SET ".
"user_name = \"" . $formVars["username"] . "\", " .
"user_passwd = \"" . $formVars["loginPassword"] . "\", " .
"user_firstname = \"" . $formVars["firstname"] . "\", " .
"user_lastname = \"" . $formVars["lastname"] . "\", " .
"user_email = \"" . $formVars["email"] . "\", " .
"user_phone = \"" . $formVars["phone"] . "\" .
" WHERE user_id = \"" . $userID . "\"";

M. Brooks
 
hi,
I tried that, but its now giving this error message...

Parse error: parse error, unexpected T_STRING
 
the error is pointing to the following line...
" WHERE user_id = \"" . $userID . "\"";
 
Simply adding quotes, ex: \"" to the insert doesn't do the trick because fields that contain quotes or ' or other characters will result in MYSQL errors.

MYSQL has a "prepare" function that returns the given variable for input into the database.

ex:
in perl you can do something like this
$fixed= $dbh->quote($formVars["username"]);

However, you seem to be using PHP so it probably has its own way of interfacing with the mysql variable preparation handler.
 
You are missing a set of bouble quotes before the where clasue:

Code:
$query = "UPDATE ATAMA_users SET ".
"user_name = \"" . $formVars["username"] . "\", " .
"user_passwd = \"" . $formVars["loginPassword"] . "\", " .
"user_firstname = \"" . $formVars["firstname"] . "\", " .
"user_lastname = \"" . $formVars["lastname"] . "\", " .
"user_email = \"" . $formVars["email"] . "\", " .
"user_phone = \"" . $formVars["phone"] . "\"[red]"[/red] .
" WHERE user_id = " . $userID . "\"" ;


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top