Page 1 of 1

MySQL Update query syntax...

Posted: Mon Dec 09, 2002 2:26 pm
by DynamiteHost

Code: Select all

$query = mysql_query("UPDATE users SET $type='$buyitem', gold='$gold' WHERE id='$usercookie'") or die ("Unable to update equipment.");
When I try to run this I get the "Unable to update equipment." error...

I've tried echoing out $buyitem, $gold, $type and $usercookie and there isn't anything wrong there... the table is definately there also...

thanks :)

Posted: Mon Dec 09, 2002 5:25 pm
by dusty
use or die(mysql_error())

Posted: Mon Dec 09, 2002 7:34 pm
by Gen-ik
Try this...

Code: Select all

<?php

$query=mysql_query( "UPDATE users SET $type='$buyitem' AND gold='$gold' WHERE id='$usercookie' ") or die ( mysql_error() );

?>
...if that doesn't work make sure all of your variables are set.

Posted: Mon Dec 09, 2002 11:00 pm
by phice

Code: Select all

<?php
$query = mysql_query("UPDATE users SET `type` = '$buyitem', `gold` = '$gold' WHERE `id` = '$usercookie'") or die (mysql_error());
?>
1st) you had a table column name 'type' as $type, not 'type'.
2nd) put ``s around table column names, and ''s around the columns value
3rd) use mysql_error() in the die();

Posted: Mon Dec 09, 2002 11:19 pm
by Sunthas
Why would you want to use `s around the table names?

Posted: Tue Dec 10, 2002 12:02 pm
by DynamiteHost
it's supposed to be $type as I mentioned in my first post which has nothing to do with the error as I have tried it with and without.

Re: MySQL Update query syntax...

Posted: Tue Dec 10, 2002 1:18 pm
by puckeye
DynamiteHost wrote:

Code: Select all

$query = mysql_query("UPDATE users SET $type='$buyitem', gold='$gold' WHERE id='$usercookie'") or die ("Unable to update equipment.");
When I try to run this I get the "Unable to update equipment." error...

I've tried echoing out $buyitem, $gold, $type and $usercookie and there isn't anything wrong there... the table is definately there also...

thanks :)
HI,

What I like to do when querying is to separate the query string and the mysql_query command like so:

Code: Select all

<?php
$query = "UPDATE users SET $type='$buyitem', gold='$gold' WHERE id='$usercookie'";
$result = mysql_query($query) or print mysql_error()."<BR>".$query;

?>
That way using or print mysql_error()."<BR>".$query I can easily find what was the error and if PHP somehow misinterpreted my query string.

Puckeye