Can't see the syntax error in this statement..HELP?

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

Can't see the syntax error in this statement..HELP?

Post by jellis00 »

I am using the below PHP statement in an IF/ELSEIF block to test content of a variable to determine whether to put the content in a particular table field of my database (in this case '15hour') and I get the following error. Can anyone help me to identify the syntax error....I have studied it for a couple of hours and can't figure it out.

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 ''15hour' = '75' WHERE iChipID ='theSerial'' at line 1

Code: Select all

} elseif ($theHour == "15"){
	mysql_query( "UPDATE temphistory SET '15hour' ='$theTemp' WHERE iChipID ='theSerial' ") or die(mysql_error() ); 
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Can't see the syntax error in this statement..HELP?

Post by internet-solution »

you used single quote around field name '15hour' - use backticks `15hour`
jellis00
Forum Newbie
Posts: 13
Joined: Mon Nov 28, 2011 2:52 pm

Re: Can't see the syntax error in this statement..HELP?

Post by jellis00 »

internet-solution wrote:you used single quote around field name '15hour' - use backticks `15hour`
OK, made that change. Now I get the following error on the below listed code:
Connected to mysql.
Couldn't execute query: Table 'jellis00.temperaturehistory' doesn't exist

Code: Select all

$host = "jellis00.db.2694804.hostedresource.com";
$user = "jellis00";
$passwd = "password";
$dbname = "jellis00";
$cxn = mysql_connect($host,$user,$passwd) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
echo "<br />Connected to mysql.<br />";
// 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 `iChipID` ='$theSerial' ") or die(mysql_error());
 	//echo $result ;
 	$query = "UPDATE temperaturehistory SET $theField = '$theTemp'
 	          WHERE `iChipID` ='$theSerial' ";
 	$result = mysql_query($query)
 			  or die("Couldn't execute query: "
 		              .mysql_error());

internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Can't see the syntax error in this statement..HELP?

Post by internet-solution »

As the error message says - the table temperaturehistory is missing. Check if this table is present and you are spelling it correctly.
jellis00
Forum Newbie
Posts: 13
Joined: Mon Nov 28, 2011 2:52 pm

Re: Can't see the syntax error in this statement..HELP?

Post by jellis00 »

internet-solution wrote:As the error message says - the table temperaturehistory is missing. Check if this table is present and you are spelling it correctly.
Stupid error on my part...the table's name is actually temphistory. I made the change in the code and it now runs without error. Now working as intended. Thanks so much for all your advice and help!
Post Reply