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: Quote 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. 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 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. Quote $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()) 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); 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; } ?> 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
Archived
This topic is now archived and is closed to further replies.