I am getting a warning in php while running my application
HTML code:
<a href="cart.html" class="dropdown-toggle" data-toggle="dropdown"><span> <?php if($a==true) { ?><?php echo $d->n; ?> <?php } ?></span></a>
PHP code:
$q=$mysqli->query("select object from object_store where Email='$email' ");
$r=$q->fetch_assoc();
$d=unserialize($r['object']);
if(!is_null($d))
{
$a=true;
}
else
{
$a=false;
}
The warning is cant call a member function on non object. I know that at first the value of $d is NULL but having used $a variable for check still the code block of $d is getting executed. Please suggest a way to remove this warning.
$q->fetch_assoc();since it is the only line in your code that actually uses any object. Actually this is a pretty typical error that has been answered endless times before: you do not do any error checking or handling at all. you blindly trust that your query well succeed. Most likely it does not succeed, but the call returns a boolean false. You cannot call a method on a boolean value.