RE: [PHP] testing a query for success--code doesnt work
| From: | (Edward Peloke) | Date: | Tue, 04 Feb 2003 21:54:48 +0000 |
| Subject: | RE: [PHP] testing a query for success--code doesnt work | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134338@lists.php.net to get a copy of this message | ||
thanks!...my fault... I had never used it...been using mysql_num_rows so
that is where I took the example.
Thanks!
Eddie
-----Original Message-----
From: Kevin Stone [mailto:kevin@helpelf.com]
Sent: Tuesday, February 04, 2003 4:53 PM
To: Edward Peloke; php-general@lists.php.net
Subject: Re: [PHP] testing a query for success--code doesnt work
FYI unlike the other mysql result functions mysql_affected_rows() works on
the last query *only* and does not accept a results pointer as input.
So this will result in an error...
$result = mysql_query("UPDATE.. whatever");
$affected_rows = mysql_affected_rows($result); //<== invalid identifier
Simply leave the $result out of the function...
$result = mysql_query("UPDATE.. whatever") or die("Invalid query.");
$affected_rows = mysql_affected_rows();
if ($affected_rows == 0)
echo "<font color=red>The query ran but no rows were updated.</font>";
else
echo "<font color=green>".$affected_rows." were
updated.</font>";
-Kevin
----- Original Message -----
From: "Edward Peloke" <epeloke@echoman.com>
To: <php-general@lists.php.net>
Sent: Tuesday, February 04, 2003 2:16 PM
Subject: RE: [PHP] testing a query for success--code doesnt work
> Just grab your qu
>
> <?
> $affected_rows = mysql_affected_rows($query);
> if ($affected_rows==0){
> print "No rows updated";
> }
> else{
> print $affected_rows." rows have beenupdated.";
> }
>
> ?>
> or something along those lines...but also add in your check to see if the
> query ran without errors.
>
> Eddie
>
>
> -----Original Message-----
> From: Sunfire [mailto:rusty_81@msn.com]
> Sent: Tuesday, February 04, 2003 4:03 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] testing a query for success--code doesnt work
>
>
> yes that is what i needed.. how many rows were changed as well as how did
> the query run in general... i want the:
> if($query){
> ok message
> }
> else{
> fail message
> }
> but i also want a query test that goes something like this:
> if(0 rows were updated){
> message saying nothing happened
> }else{
> message saying the record was actually updated
> }
> if i can get some code example for that...it would help
>
> tnx
>
> ----- Original Message -----
> From: "Edward Peloke" <epeloke@echoman.com>
> To: <php-general@lists.php.net>
> Sent: Tuesday, February 04, 2003 3:46 PM
> Subject: RE: [PHP] testing a query for success--code doesnt work
>
>
> > I believe as long as the update was successful (no errors) it will say
> > 'message if successful'...I think you are wanting to know if rows were
> > updated or not...not whether or not the query ran ok.
> >
> > Eddie
> >
> > -----Original Message-----
> > From: Sunfire [mailto:rusty_81@msn.com]
> > Sent: Tuesday, February 04, 2003 3:51 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] testing a query for success--code doesnt work
> >
> >
> > 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?
> >
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/2003
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>