Re: testing a query for success--code doesnt work

From: Date: Tue, 04 Feb 2003 20:51:33 +0000
Subject: Re: testing a query for success--code doesnt work
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134329@lists.php.net to get a copy of this message
At 21:51 4-2-2003, you wrote:
hi.. posted a message about what the code was to test an update query to see if it was successfull using mysql and i tested my code and for some reason even if none of the fields were updated it still reports the success message... heres the code i have: $query=mysql_query("update members set company="\$company\", ........); if($query){ message if successfull... } else{ message if not or if failed..//never gets used } anybody know why this doesnt work if 0 records were changed?
* if the update does not have anything to work on it does not mean it is a failure! except when you EXPECTED it to update something. * i'm not sure whether "if ($query) " is the proper way to check this. for trapping development errors i always suggest: $q="update members set company="\$company\", ........ $query=mysql_query($q) or
         die ('<hr>DB update failed in '.__FILE__.' line '.__LINE__.'<br>Query was:'.$q.'<br>mysql reported:'.mysql_error());
* for counting the affected rows use http://nl.php.net/manual/nl/function.mysql-affected-rows.php

« previous php.general (#134329) next »