Click to See Complete Forum and Search --> : Update where: LOSING MY MIND!


ineedasn
10-20-2008, 05:31 PM
Ok I keep getting an error for this that says my syntax is wrong near "order=7". If I change it to any other column than "order", it works perfectly fine. What could possibly make that happen? This is driving me insane! Heres the code:

<?
session_start();
$uid = $_SESSION['id'];
include("dbcon.php");

$title = $_POST['title'];
$noteid = $_POST['tnum'];



$request = "UPDATE notes SET title='$title' WHERE (user=$uid AND order=$noteid)";

$query = mysql_query($request) or die(mysql_error());

if($query){
echo "Success";
}else{
echo "FFAILURE!!! - ".$request;
}

?>

I cant figure this out...

Shorts
10-20-2008, 05:43 PM
What does your table look like? In particular what type of field is order?

also, try throwing some single quotes and backticks up. sometimes theres weird glitches:


$request = "UPDATE `notes` SET `title`='$title' WHERE `user`=$uid AND `order`='$noteid'";

ineedasn
10-20-2008, 05:54 PM
Wow... thanks. I don't know what the problem was, but I guess the backticks did it. Speaking of which what do they do? I'd never heard of using them. I actually had to look at my keyboard to find the key for them. haha

gabriele
10-20-2008, 06:04 PM
well it is not weird glitches...

it is just that the work order is a reserved keyword in sql language ( reserved for ordering results ) ..

i am not sure about mysql (i suppose that is what you use), but in mssql you can always use field names with []
so and order = $noteid should be and [order] = $noteid

regards

Shorts
10-20-2008, 06:27 PM
good call gabriele. and yeah, for mysql thats the use of the back tick `