Page 1 of 1

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

Posted: Sat Dec 03, 2011 5:00 pm
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() ); 

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

Posted: Sat Dec 03, 2011 6:48 pm
by internet-solution
you used single quote around field name '15hour' - use backticks `15hour`

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

Posted: Sat Dec 03, 2011 6:59 pm
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());


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

Posted: Sat Dec 03, 2011 7:06 pm
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.

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

Posted: Sat Dec 03, 2011 7:25 pm
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!