-2

I have a problem with my SQL Syntax.. All other SQL-Methods are correct in my files but a UPDATE-Method fails everytime. I can't find the mistake. Please help me.

$sql = mysql_query("UPDATE ".$dbName.".'settings' SET 'interval'=".$intervalValue." WHERE 'settingID'=0 ");

The error of my debug-method is:

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 ''settings' SET 'interval'=2800 WHERE 'settingID'=0' at line 1
DerFuchs10
  • 135
  • 1
  • 2
  • 12
  • give us the output of `"UPDATE ".$dbName.".'settings' SET 'interval'=".$intervalValue." WHERE 'settingID'=0 "`, it seems `$dbName` is `'` – rcpayan May 18 '13 at 11:20

4 Answers4

1
$sql = mysql_query('UPDATE `' . $dbName . '`.`settings` SET `interval` = ' . $intervalValue . ' WHERE `settingID` = 0;');
Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89
1
$sql = mysql_query("UPDATE ".$dbName.".`settings` SET 'interval'=".$intervalValue." WHERE 'settingID'=0 ");

You should mark databases & tables with "`" instand of "'".

Raz Harush
  • 739
  • 1
  • 6
  • 21
0

You did the quoting wrong. Use single quotes to quote the values and not the column names, use the proper MySQL quoting with ticks for table and column names

"UPDATE ".$dbName.".`settings` SET SET `interval`='".$intervalValue."' WHERE `settingID`=0"
Havelock
  • 6,913
  • 4
  • 34
  • 42
0

You should protect your code against SQL injection : How can I prevent SQL injection in PHP?

$sql = mysql_query("UPDATE ".$dbName.".settings SET interval='".$intervalValue."' WHERE settingID=0 ");
Community
  • 1
  • 1
sdespont
  • 13,915
  • 9
  • 56
  • 97