0

Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/pbook/inc/login.in.php on line 12

<?php
include 'contacts.php';
if($_SERVER['REQUEST_METHOD']=='POST'&& $_POST['submit']=='Login')
{
    $lname = isset($_POST['lname']) ? trim($_POST['lname']):NULL;
    $lpwd = isset($_POST['lpwd']) ? trim($_POST['lpwd']):NULL;

    if(($lname!=NULL)&&($lpwd!=NULL))
    {
        $lobj=new DB_Action();
        $l=$lobj->disp("Select * From members where memname= '$lname'and mempass='$lpwd'");
        foreach ($l as $result)
        {
            $aid =$result['memid'];
            $_SESSION['_ENTER'] =1;
            header("location:address-book.php?l=$aid");
            exit;
        }

    }
}
?>
4
Contributors
3
Replies
15
Views
4 Years
Discussion Span
Last Post by diafol
0

You probley have an error in your query.
(assuming $lobj->disp returns false on fail just like mysql_query)

0

The foreach construct provides an easy way to iterate over arrays. foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable.

So according to above quote from PHP manual,your previous statement is not returning any array/objects.

Most probably error is there in your $lobj->disp("Select * From members where memname= '$lname'and mempass='$lpwd'");

Please show the disp method.Is this running the mysql query and returning arrays???

0

Try

print_r($l); exit;

Just before the foreach loop. See what it contains.

In addition, you seem to be using unsanitized input data in your SQL.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.