Gossamer Forum
Home : General : Databases and SQL :

mysql & php: cannot update field

Quote Reply
mysql & php: cannot update field
Hi,



My code in php:

$query = "update $BOOKS set UserID = '$userid' where ID = $bid";


$result = mysql_query($query,$DB) or die ("Error in executing $query. Reason:". mysql_error($DB));

If I echo the query I can execute via phpmyadmin, but I cannot execute in the php code.

Please tell me how to solve this.

Thanks in advance,



Beck
Quote Reply
Re: [Beck] mysql & php: cannot update field In reply to
If you UserID is an Integer field, then you don't need to use single quotes.

Try the following:

Code:
$query = "update $BOOKS set UserID = $userid where ID = $bid";
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Beck] mysql & php: cannot update field In reply to
Didn't the error catching stuff give you anything? I would have used a different approach for error checking too...

Code:
$result = mysql_query($query,$DB);
$error = mysql_error();
if ($error) {
echo "SQL Error: Query \"$query\" gave the following error from MySQL: \n\n$error";
exit;
}

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates