Jump to content


Photo

Screwy mysql_affected_rows() Problem


  • Please log in to reply
2 replies to this topic

#1 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 11 June 2006 - 09:56 PM

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:

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

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 has updated properly.

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

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 June 2006 - 11:14 PM

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:
if (mysql_affected_rows() != 1) {

Legend has it that reading the manual never killed anyone.
My site

#3 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 11 June 2006 - 11:26 PM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users