Jump to content

Screwy mysql_affected_rows() Problem


WendyLady

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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.