Jump to content

mysqli fetch_object() on non-object issue


dragon_sa

Recommended Posts

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");
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.