Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
DynamiteHost
Forum Commoner
Posts: 69 Joined: Sat Aug 10, 2002 5:33 pm
Post
by DynamiteHost » Mon Dec 09, 2002 2:26 pm
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
dusty
Forum Contributor
Posts: 122 Joined: Sun Apr 28, 2002 9:52 pm
Location: Portsmouth, VA
Post
by dusty » Mon Dec 09, 2002 5:25 pm
use or die(mysql_error())
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Mon Dec 09, 2002 7:34 pm
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.
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Mon Dec 09, 2002 11:00 pm
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();
Sunthas
Forum Newbie
Posts: 9 Joined: Sun Dec 08, 2002 12:43 am
Post
by Sunthas » Mon Dec 09, 2002 11:19 pm
Why would you want to use `s around the table names?
DynamiteHost
Forum Commoner
Posts: 69 Joined: Sat Aug 10, 2002 5:33 pm
Post
by DynamiteHost » Tue Dec 10, 2002 12:02 pm
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.
puckeye
Forum Contributor
Posts: 105 Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:
Post
by puckeye » Tue Dec 10, 2002 1:18 pm
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