Forum Moderators: coopster

Message Too Old, No Replies

mysql affected rows

error using mysql_affected_rows in PHP

         

snowman304

1:03 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



I am getting this error:

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource

Here is the code I am using:

$sql = "UPDATE log SET wTemp = '$thiswTemp' , wSpeed = '$thiswSpeed' , wDirection = '$thiswDirection' , sky = '$thissky' , precipitation = '$thisprecipitation' , pressure = '$thispressure' , moon = '$thismoon' , spot = '$thisspot' , waterName = '$thiswaterName' , waterTemp = '$thiswaterTemp' , city = '$thiscity' , state = '$thisstate' , clarity = '$thisclarity' , bottom = '$thisbottom' , bType = '$thisbType' , bName = '$thisbName' , rig = '$thisrig' , species = '$thisspecies' , length = '$thislength' , weight = '$thisweight' , cTime = '$thiscTime' , cDate = '$thiscDate' , cDepth = '$thiscDepth', notes = '$thisnotes'
WHERE id='$thisid' AND userid='$_SESSION[USERID]' ";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
echo $sql;
$numberOfRows = mysql_affected_rows($result);

This error happens when I inserted the AND userid='$_SESSION[USERID]' in WHERE. In phpmyadmin, if I use my code above, it updates, but it says 0 rows affected. If I take out the userid part, it updates and says 1 rows affected. either way, it updates, but produces a different rows affected.

What I am trying to do is make sure the row being updated is equal to the row id that it is assoc. with and also that the row belongs to the user that is trying to update it.

Any suggestions?

Thanks for any help.
-Mike

Habtom

8:28 am on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try putting just the following:

$numberOfRows = mysql_affected_rows();

Habtom

snowman304

8:39 am on Jul 30, 2007 (gmt 0)

10+ Year Member



Thanks. That fixed it.

Thanks again.

-Mike