Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Login function help

$
0
0
Hi, basically I have this snippet some of which I am trying to move into a function. In its current form it works OK, but when I try to call for it within my function it does not :
 
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\1\assets\includes\memberfunc.php on line 18
 
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\1\login.php on line 106
Acess denied, wrong username or password?
 
Here's the function.
 
function logcon($user, $password )
{
    
   $esc_user = mysqli_real_escape_string($this->conn, $user);
   $esc_password = mysqli_real_escape_string($this->conn,$password);  
$sql = "select * all from users where username  ='{$user}' AND password='{$password}'";
 $result = mysqli_query($this->conn, $sql);
  
              $row = mysqli_fetch_array($this->conn, $result);
            return $row;
            }
 
Here's the old, working code.
 
if(isset($_POST['submit'])){
 
$user=$_POST['user']; 
$password=$_POST['password'];
 
 
//To ensure that none of the fields are blank when submitting the form if
if(isset($_POST['user']) && isset($_POST['password'])) 
{    
    
    
$user = stripslashes($user);
$password = stripslashes($password);
    
$db1=new dbmember();
$db1->openDB();                 
$sql="SELECT * FROM users WHERE username='{$user}' AND password='{$password}'";
 
 
$result=$db1->logcon($user, $password);
$row=mysqli_fetch_array($result);
 
if($row[0]==1)
{
    session_start();
    $_SESSION['user'] = $user;
    $_SESSION['password'] = $password;
    $_SESSION['loggedin'] = "true";
    header("location:index.php");
}
 
Any help on this would be fantastic. I'm pretty stuck.

Viewing all articles
Browse latest Browse all 13200

Trending Articles