Page 1 of 1

mysql query problem

Posted: Thu Mar 23, 2006 6:19 am
by raymedia
i am trying to make this query. but it gaves me error. I realize that this is caused by the field name "FOR" but it's a snycro for a dept. is there anyway around this issue? so i won't get this error. i tried put quotes around the word - 'FOR' but it still not working. even if you direct me to the resources, it'll be great.

Thank you very much in advance.

Code: Select all

$table = "staff";
$field_name = "FOR";
update $table set $field_name='1' where id_staff='$id_staff';

Posted: Thu Mar 23, 2006 6:27 am
by JayBird
use backticks

Code: Select all

$table = "staff";
$field_name = "FOR";


$sql = "UPDATE `$table` SET `$field_name` = '1' WHERE `id_staff` = '$id_staff'";

Posted: Thu Mar 23, 2006 6:28 am
by Benjamin

Code: Select all

$query = "update `staff` set `FOR`='1' where `id_staff`='" . $id_staff . "'";
EDIT- Arg ya beat me.

thakn you Masters

Posted: Thu Mar 23, 2006 6:35 am
by raymedia
It works!!! really appriciate it :) Cheers