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
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!