Jump to content

Login function help


Apeshape

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/280721-login-function-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.