2

I've been staring at this thing for a while now and I can't seem to figure out what the syntax error is. I've been in this situation before and last time it was something so unbelievably simple I felt stupid afterwards. But here's to another attempt:

//update database
$q = "
 UPDATE 
  users 
 SET 
  id='$edit_id',
  name='$edit_name',
  bdm='$edit_bdm',
  add='$edit_add',
  pc='$edit_pc',
  location='$edit_outletL',
  style='$edit_outletS',
  coName='$edit_coName',
  coNum='$edit_coTel',
  coEmail='$edit_coEmail',
  password='$edit_pass'
 WHERE
  id='$query_title'
";
$edit_query = mysql_query($q) or die("Database Query Error: ". mysql_error());

Database Query Error:

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 'add='Llancadle, Nr Barry', pc='CF62 3AQ', location='rural', style='food', coName' at line 1
Bobby
  • 11,419
  • 5
  • 44
  • 69
Dan Hanly
  • 7,829
  • 13
  • 73
  • 134

4 Answers4

4

You neeed to backquote add since it is a keyword:

`add` = ...
Nylon Smile
  • 8,990
  • 1
  • 25
  • 34
3

I think add is a reserved word in MySQL.

Shikiryu
  • 10,180
  • 8
  • 49
  • 75
2

your problem is that "add" is a MySQL reserved word. See: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html. If you have a column named "add", escape it like this:

//update database
    $edit_query = mysql_query("UPDATE users SET id='$edit_id', name='$edit_name', bdm='$edit_bdm', `add`='$edit_add', pc='$edit_pc', location='$edit_outletL', style='$edit_outletS', coName='$edit_coName', coNum='$edit_coTel', coEmail='$edit_coEmail', password='$edit_pass' WHERE id='$query_title'") or die("Database Query Error: ". mysql_error());
Spiny Norman
  • 8,277
  • 1
  • 30
  • 55
2

as bobby noted in a comment, add is a mysql reserved word

`add`='$edit_add'

will tell mysql you are talking about a column

Alan Whitelaw
  • 16,171
  • 9
  • 34
  • 51