2 Replies - 743 Views - Last Post: 08 June 2013 - 07:21 AM Rate Topic: -----

#1 UnknownCoder   User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 137
  • Joined: 22-February 09

SQL Update Command Syntax Error

Posted 08 June 2013 - 05:25 AM

I'm having a problem updating the values in my SQL database. Here is the error I'm getting:

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 '@gmail.co, WHERE id=2' at line 1


This is the code I've created for it:

// save the account info if the button was pressed.
if(isset($_POST['save_account'])){

	$id = $_SESSION['id'];
	$realname = $_POST['realname'];
	$email = $_POST['email'];
	
	$realname = mysql_real_escape_string($realname);
	$email = mysql_real_escape_string($email);
	
	mysql_query("UPDATE `users` SET `realname`=$realname, `email`=$email, WHERE `id`=$id") or die(mysql_error());
	$_SESSION['success'] = 'Your site settings have been successfully updated.';

}


If anyone could help me with this, it would be much appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: SQL Update Command Syntax Error

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: SQL Update Command Syntax Error

Posted 08 June 2013 - 06:04 AM

you want to pass strings, but strings must be quoted in SQL (unless you use Prepared Statements, see signature)
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: SQL Update Command Syntax Error

Posted 08 June 2013 - 07:21 AM

You also have an extra comma after $email.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1