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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jellis00
Forum Newbie
Posts: 13
Joined: Mon Nov 28, 2011 2:52 pm

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

Post 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>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

Always a good idea to quote table & column names with the backtick `
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
jellis00
Forum Newbie
Posts: 13
Joined: Mon Nov 28, 2011 2:52 pm

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

Post 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:
Post Reply