Kemik Posted July 30, 2007 Share Posted July 30, 2007 Hello all, I'm updating a row and checking if it worked. Please post your own version of the code if you feel this is over complicating it or just won't work at all. <?php $q = "UPDATE ".TBL_CLAN_MEMBERS." SET approve = '1' WHERE username = '$user'"; $result = mysql_query($q, $this->connection); if(!$result || (mysql_affected_rows($result) < 1)){ return NULL; } ?> The code updates the table as I want, however it then gives the following error: Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/sh/public_html/ocwars/include/database.php on line 313 I've tried replacing mysql_affected_rows() with mysql_num_rows() but the same error occurs. Quote Link to comment https://forums.phpfreaks.com/topic/62565-solved-testing-if-a-query-returned-something/ Share on other sites More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 You want to supply the mysql link resource, not the result object from the query.... $conn = mysql_connect(.......); //$conn would be the mysql link resource $result = mysql_query(......); //$result would be the mysql result object Quote Link to comment https://forums.phpfreaks.com/topic/62565-solved-testing-if-a-query-returned-something/#findComment-311400 Share on other sites More sharing options...
Kemik Posted July 30, 2007 Author Share Posted July 30, 2007 $this->connection does the main connecting to the server. $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()) Quote Link to comment https://forums.phpfreaks.com/topic/62565-solved-testing-if-a-query-returned-something/#findComment-311404 Share on other sites More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 Then reference that connection in your mysql_affected_rows call. If you're in the class, use the $this syntax, if your outside the class, and the connection is "public" you can reference it through the object... $db = new database_connection(); .... code for query .... echo mysql_affected_rows($db->connection); Quote Link to comment https://forums.phpfreaks.com/topic/62565-solved-testing-if-a-query-returned-something/#findComment-311410 Share on other sites More sharing options...
trq Posted July 30, 2007 Share Posted July 30, 2007 <?php $q = "UPDATE ".TBL_CLAN_MEMBERS." SET approve = '1' WHERE username = '$user'"; $result = mysql_query($q, $this->connection); if(!$result || !mysql_affected_rows()) { return FALSE; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62565-solved-testing-if-a-query-returned-something/#findComment-311414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.