dragon_sa Posted March 26, 2012 Share Posted March 26, 2012 I am getting an error when the clear banned ip over 15mins script runs if there is a row to remove from the database, what am I doing wrong here and the error is PHP Fatal error: Call to a member function fetch_object() on a non-object in /path/to/file/index.php on line 14 <?php // clear banned ip over 15mins $timeBAN = time(); $sql = $link->query("SELECT unban, id FROM attempts WHERE unban <= '$timeBAN'"); if ($sql->num_rows > 0) { while ($result = $sql->fetch_object()) { //<----THIS IS LINE 14 CAUSING ERROR if there is data $remove=$result->id; $sql = $link->query("DELETE FROM attempts WHERE id='$remove'"); } $sql->close(); } // check if user banned $sql = $link->query("SELECT ip, unban FROM attempts WHERE ip='$ip'"); if ($sql->num_rows > 0) { $result = $sql->fetch_object(); $unban = $result->unban; $timeCHECK = $unban-$timeBAN; if ($timeCHECK > 0 ) { $remain = round($timeCHECK/60); } $sql->close(); } // reset the auto_increment of attempts $sql = $link->query("SELECT id FROM attempts"); if ($sql->num_rows == 0) { $sql = $link->query("ALTER TABLE attempts AUTO_INCREMENT = 1"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259720-mysqli-fetch_object-on-non-object-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2012 Share Posted March 26, 2012 You are overwriting the $sql variable inside the while(){} loop, so the second time through the loop it no longer contains the result object from the SELECT query. Quote Link to comment https://forums.phpfreaks.com/topic/259720-mysqli-fetch_object-on-non-object-issue/#findComment-1331132 Share on other sites More sharing options...
dragon_sa Posted March 26, 2012 Author Share Posted March 26, 2012 Doh!! bit of an oversight I am just converting from my mysql ways to mysqli so still getting use to it Quote Link to comment https://forums.phpfreaks.com/topic/259720-mysqli-fetch_object-on-non-object-issue/#findComment-1331133 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.