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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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