Jump to content

Archived

This topic is now archived and is closed to further replies.

WendyLady

Screwy mysql_affected_rows() Problem

Recommended Posts

Hi everyone --

I have an interesting thing happening that is just annoying, but interesting. I can work around it, but I would really like to know why it is happening.

I have an option on a form that either UPDATEs or DELETEs a row in the MySQL database. After each one, I have the following code to confirm the UPDATE or DELETE:

[code]if (mysql_affected_rows != 1) {
                echo 'Problem!';
                echo '<br />' . mysql_affected_rows() . $query;
            }else{
                header ("Location: index.php");
            }[/code]

The screwy thing is, for the UPDATE query it returns "Problem! 1 (affected row)" and then the query. And when I check the database, it [b]has updated properly[/b].

For the DELETE query, it returns "Problem! 0 (affected rows)" and then the query. And when I check the database, it [b]has deleted properly[/b].

Why would it be going into the "if !=1" when it IS equal to 1, and why would it be returning 0 affected rows when there IS an affected row? I have stated the above in a variety of ways, such as reversing it to "if ==1", "if ==0 || if == -1", etc., to no avail!

Have you seen this before? Am I making a stupid mistake that is causing it?

Darn curious (and Thank you!),

Wendy

Share this post


Link to post
Share on other sites
mysql_affected_rows is meaningless - either it's a function and you forgot the parentheses [see below], or you intended it as a variable and it needed a $ ... How about this:
[code]if (mysql_affected_rows() != 1) { [/code]

Share this post


Link to post
Share on other sites
Well, shoot. I think I've been working on it too long. I just advised someone else to take a break, and now I think it is time for me to do so, too.

LOL -- thank you!

Wendy

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.