Trying to get property of non-object
<p>This script works great. I call it in top of my scripts. But if a user that is NOT banned enters the site they get:</p>

<pre><code>Notice: Trying to get property of non-object in index.php on line 20
</code></pre>

<p>The function:</p>

<pre><code>// Check if conecting user is banned. If ban has expired delete row.
function check_bans()
{

// IP address
$user_ip = $_SERVER['REMOTE_ADDR'];

$query = mysql_query("SELECT ip, expire FROM bans WHERE ip = '$user_ip'");
$row = mysql_fetch_object($query);

$expire = $row-&gt;expire ? date('M d Y H:i', $row-&gt;expire) : 'Never';

// Did we find a match?
if (mysql_num_rows($query)) {

    // Has this ban expired? Then delete and let user inside.
    if ($row-&gt;expire != '' &amp;&amp; $row-&gt;expire &lt;= time())
        mysql_query("DELETE FROM bans WHERE ip = '$user_ip'") or die (mysql_error());
    else
        die("&lt;h1 align=\"center\" style=\"color:maroon\"&gt;You have been IP banished. Ban will be lifted: $expire&lt;/h1&gt;");

}

}
</code></pre>
