Forum Moderators: coopster

Message Too Old, No Replies

parse error, unexpected T_STRING

         

pluto2

7:37 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



Hi there
I'm a flash developer who's had to learn php for some database access... lucky me:)

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;)

jatar_k

7:42 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld pluto2,

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.

pluto2

8:02 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



thankx for the welcome!
and the quick reply...

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!

jatar_k

8:09 pm on Aug 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, I never use backticks but who knows whether purists will string me up or not ;)

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.

pluto2

8:16 pm on Aug 22, 2005 (gmt 0)

10+ Year Member



hehe, I'm giddy with appreciation here mate..

thanks a shed load, the no-quotes method worked to a tee:)
php headache dissapating as I type!

thanks again!

DaButcher

11:51 am on Aug 23, 2005 (gmt 0)

10+ Year Member



look up:
www.php.net/mysql_real_escape_string , for your own security!