Connecting Tech Pros Worldwide Help | Site Map

udate command SQL Error

ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#1: Nov 19 '08
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]
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Nov 19 '08

re: udate command SQL Error


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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#3: Nov 19 '08

re: udate command SQL Error


there might be something wrong with the connection resource. check if $dbLink is valid.

regards
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#4: Nov 19 '08

re: udate command SQL Error


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]
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,635
#5: Nov 20 '08

re: udate command SQL Error


additional note:
another common way to catch a db error is
[PHP]mysql_query($sql) or die("DB Error " . mysql_errno() . ": " . mysql_error());[/PHP]
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#6: Nov 20 '08

re: udate command SQL Error


Thanks Dormilich for the additional info
Reply