Page 1 of 1

Help with a syntax error I can't find in UPDATE query?

Posted: Thu Dec 01, 2011 2:12 am
by jellis00
My browser is displaying the following indication of the error:
[text]Connected to mysql.
Resource id #7You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0 ='xxx' WHERE loginName='jellis00 '' at line 1[/text]
It is obviously pointing at the BOLDED statement in below code segment. Can anyone please help me find and explain the error????...I have spent hours studying this problem and any help would be appreciated.

Code: Select all

<?php 
//Store latest temperature reading in appropriate time slot in mysql DB table "temphistory"
mysql_connect("jellis00.db.2694804.hostedresource.com", "jellis00", "password") or die(mysql_error());
echo "<br />Connected to mysql.<br />";
mysql_select_db("jellis00") or die(mysql_error());
// Point to the record for the logged in iChip Serial_no
   // Get a specific result from the table that contains the value in $theSerial
	$result = mysql_query("SELECT * FROM temphistory
 		WHERE loginName='jellis00' ") or die(mysql_error());
 	echo $result ;
 	mysql_query("UPDATE temphistory SET iChipID= '$theSerial' 
 		WHERE loginName='$loginName' ");
 		  
// Determine the hour of the temperature measurement and store measurement in appropiate field
if ($theTime = "00:00"){
	[b]mysql_query("UPDATE temphistory SET 0 ='$theTemp' WHERE loginName='$loginName' ") or die(mysql_error());[/b]
} elseif ($theTime = "01:00"){
	mysql_query("UPDATE temphistory SET 1 ='$theTemp' WHERE loginName='$loginName' ") or die(mysql_error());
} elseif ($theTime = "02:00"){
	mysql_query("UPDATE temphistory SET 2 ='$theTemp' WHERE loginName='$loginName' ") or die(mysql_error());
} elseif ($theTime = "03:00"){
	mysql_query("UPDATE temphistory SET 3 ='$theTemp' WHERE loginName='$loginName' ") or die(mysql_error());
// etc, etc, etc
?p>

Re: Help with a syntax error I can't find in UPDATE query?

Posted: Thu Dec 01, 2011 2:57 am
by social_experiment
I'm guessing the problem is with the column name being a digit
Sql Manual wrote:Identifiers may begin with a digit but unless quoted may not consist solely of digits.

Re: Help with a syntax error I can't find in UPDATE query?

Posted: Thu Dec 01, 2011 3:52 pm
by pickle
Always a good idea to quote table & column names with the backtick `

Re: Help with a syntax error I can't find in UPDATE query?

Posted: Fri Dec 02, 2011 3:54 pm
by jellis00
social_experiment wrote:I'm guessing the problem is with the column name being a digit
Sql Manual wrote:Identifiers may begin with a digit but unless quoted may not consist solely of digits.
That was the problem. Thanks so much for pointing that out. I had checked the PHP manual but didn't think of checking the SQL Manual. By changing the column identifiers to '0hour', '1hour', etc.(with single quotes) it solved the problem. :mrgreen: