Forum Moderators: coopster
I'm getting the above error from the following php code:
====================================
<?php
$month = $_POST['month'];
$day = $_POST['day'];
$connect = mysql_connect("blank", "blank", "blank");
mysql_select_db("blank", $connect);
$result = mysql_query('UPDATE `alanya_cal` SET '$month' = \'b\' WHERE `ID` = '$day' LIMIT 1');
if($result) echo "writing=Ok&";
else echo "writing=Error&";
?>
===========================================
Im trying to update the relevant fields with the values:
'$month' and '$day', which are passed from a swf file.
Anyone any idea what I'm doing wrong here?
cheers
ps. sorry for any noobness;)
since you didn't include a line number I am guessing this line
$result = mysql_query('UPDATE `alanya_cal` SET '$month' = \'b\' WHERE `ID` = '$day' LIMIT 1');
your quotes are all messed up.
ref
[php.net...]
put double quotes around the string since you have variables in there you want to be resolved. Something like this
$result = mysql_query("UPDATE `alanya_cal` SET '$month'='b' WHERE `ID`='$day' LIMIT 1");
not sure about the '$month', that looks strange. I am guessing those single quotes around it should be backticks.
you're right it was that line giving the problems,
the '$month' value is passed into the php file from a POST array created in the flash file.
So should I treat it with some kind of "values" php syntax?
I tried the line with the correct quotes and the T-string error disappeared... but the database wasn't updated
still stumped!
without ticks and quotes might work
$result = mysql_query("UPDATE alanya_cal SET $month='b' WHERE ID='$day' LIMIT 1");
I also do my queries like so to see what is going on
$sql = "UPDATE alanya_cal SET $month='b' WHERE ID='$day' LIMIT 1";
$result = mysql_query($sql) or die('update died: ' . mysql_error());
that will give you the error right from mysql, I also tend to echo my query so I can check it by eye. Which would be something like this
$sql = "UPDATE alanya_cal SET $month='b' WHERE ID='$day' LIMIT 1";
echo '<p>',$sql;
$result = mysql_query($sql) or die('<p>update died: ' . mysql_error());
remember to remove or comment all that testing stuff when it goes live and handle errors in a user friendly manner when there will actually be users. ;)
I also add the line number in my die statement so I don't have to look through 100 update queries or if it is done by loop then an iteration or id num. Anything that can help me identify where things went wrong.