Re: RE: [PHP] Update statement?
| From: | Scott Barron | Date: | Thu, 19 Oct 2000 13:17:56 +0000 |
| Subject: | Re: RE: [PHP] Update statement? | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-db+get-3791@lists.php.net to get a copy of this message | ||
Hi,
die is going to do just that, die on an error. Your if block won't get
executed. mysql_query returns true if the query could be executed by
MySQL, it doesn't return the number of rows affected. If you need to
verify the number of rows affected by the query use
mysql_affected_rows() Try someting like this:
// Do the query and make sure it succeeds
if (!$update = mysql_query("...", $db)) {
echo "Error occured: ".mysql_error($db);
}
// Validate the number of row affected
if (mysql_affected_rows($db)) {
echo "Row updated";
} else {
echo "Row not updated";
}
Try playing with that and seeing if that will work for you.
-Scott
Wee Chua wrote:
>
> Hi james,
> I tried your if statement and it didn't work correctly, would you correct my
> if statement if that's anything wrong. And how could display the error
> message if mysql_error() contains one? Thank you.
>
> if(!$update = mysql_query("update Employee set Name='John' where
> Id=1",$db))die("Error updateding
> records.<BR>".mysql_error($db)."");
> if (mysql_error($db)){
> echo "Row not updated";
> } else {
> echo "Row updated";}
>
> calvin
>
<SNIP>
--
-------------------------------------------------------------------------------
"That's a deer shooting hat."
"Like hell it is. This is a people shooting hat. I shoot people in
this hat."