By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 1,828 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

udate command SQL Error

ddtpmyra
100+
P: 333
I have this below script and mysql didn't get thru I tried to print the sql query every things is fine it's just somehow can't update my table. What's wrong?

[PHP]
# Gather all required data
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];

# INSERT SQL query
$query="INSERT INTO contact (FirstName,LastName)
VALUES (
'{$FirstName}',
'{$LastName}'
)";

echo "$query";
# Execute the INSERT QUERY
$result = mysql_query($query, $dbLink) ;


if($result){
echo "Successful<BR>";

}
else {
echo "ERROR";
}
mysql_close();



#Close the mysql connection
mysql_close($dbLink);

[/PHP]
Nov 19 '08 #1
Share this Question
Share on Google+
5 Replies


pbmods
Expert 5K+
P: 5,821
Heya, ddtpmyra.

Try checking for error this way:
Expand|Select|Wrap|Line Numbers
  1. if( mysql_errno() )
  2. {
  3.   exit(mysql_error());
  4. }
  5.  
http://php.net/mysql_errno
http://php.net/mysql_error
Nov 19 '08 #2

Dormilich
Expert Mod 5K+
P: 8,639
there might be something wrong with the connection resource. check if $dbLink is valid.

regards
Nov 19 '08 #3

ddtpmyra
100+
P: 333
hi pbmods,

Your syntax works I was able to catch what's my sql error is....

thanks a lot!

[PHP]if( mysql_error() )
{
exit(mysql_error());
} [/PHP]
Nov 19 '08 #4

Dormilich
Expert Mod 5K+
P: 8,639
additional note:
another common way to catch a db error is
[PHP]mysql_query($sql) or die("DB Error " . mysql_errno() . ": " . mysql_error());[/PHP]
Nov 20 '08 #5

ddtpmyra
100+
P: 333
Thanks Dormilich for the additional info
Nov 20 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.