Jump to content

Fatal error: Cannot use object of type mysqli_result as array in - Help please!


Go to solution Solved by Ch0cu3r,

Recommended Posts

Hello,

I'm coding a log in page and I keep getting this problem with mysqli_result.  It's a mysqli server.

My error is:

Fatal error: Cannot use object of type mysqli_result as array in /home/a7017672/public_html/login.html on line 34

 

 

 

My code is:

<?PHP

if(isset($_SESSION['loggedin']))
{
    die("You are already logged in!");
if(isset($_POST['submit']))
{
   $email = mysqli_real_escape_string($con,$_POST['username']); 
   $pass = mysqli_real_escape_string($con,$_POST['password']); 
   $mysql = mysqli_query($con,"SELECT * FROM users WHERE email_address = '{$email}' AND password = '{$pass}'"); 
   $mysql2 = mysqli_fetch_array($mysql);
   if (!$mysql ||mysqli_num_rows($mysql) < 1)
   {
     die("Incorrect password!");
   } 
   $_SESSION['loggedin'] = "YES"; 
   $_SESSION['email'] = $email; 
   $_SESSION['fname'] = $mysql['first_name'];
   $_SESSION['lname'] = $mysql['last_name'];
   $_SESSION['add1'] = $mysql['address_1'];
   $_SESSION['add2'] = $mysql['address_2'];
   $_SESSION['county'] = $mysql['county'];
   $_SESSION['postcode'] = $mysql['postcode'];
   $_SESSION['tel'] = $mysql['tel_no'];
   $_SESSION['mobile'] = $mysql['mobile_no'];
   $_SESSION['team'] = $mysql['team'];
   $_SESSION['ismanager'] = $mysql['is_manager'];
   $_SESSION['isadmin'] = $mysql['is_admin'];
   $_SESSION['sysadmin'] = $mysql['is_sysadmin'];
   die("You are now logged in!"); 
echo "<form method='POST'>
<p style='font-size: 14pt;'>Username (Email):  <br><input type='text' name='username' maxlength='50' size='30'>
<br />
<p style='font-size: 14pt;'>Password:<br><input type='text' name='password' maxlength='50' size='30'><br />
<input type='submit' name='submit' value='Login'>
</form>";
?>
 
 
Any help is greatly appreciated!
  • Solution

You should be using $mysql2 variable here not $mysql

   $_SESSION['fname'] = $mysql['first_name'];
   $_SESSION['lname'] = $mysql['last_name'];
   $_SESSION['add1'] = $mysql['address_1'];
   $_SESSION['add2'] = $mysql['address_2'];
   $_SESSION['county'] = $mysql['county'];
   $_SESSION['postcode'] = $mysql['postcode'];
   $_SESSION['tel'] = $mysql['tel_no'];
   $_SESSION['mobile'] = $mysql['mobile_no'];
   $_SESSION['team'] = $mysql['team'];
   $_SESSION['ismanager'] = $mysql['is_manager'];
   $_SESSION['isadmin'] = $mysql['is_admin'];
   $_SESSION['sysadmin'] = $mysql['is_sysadmin'];

 

You should be using $mysql2 variable here not $mysql

   $_SESSION['fname'] = $mysql['first_name'];
   $_SESSION['lname'] = $mysql['last_name'];
   $_SESSION['add1'] = $mysql['address_1'];
   $_SESSION['add2'] = $mysql['address_2'];
   $_SESSION['county'] = $mysql['county'];
   $_SESSION['postcode'] = $mysql['postcode'];
   $_SESSION['tel'] = $mysql['tel_no'];
   $_SESSION['mobile'] = $mysql['mobile_no'];
   $_SESSION['team'] = $mysql['team'];
   $_SESSION['ismanager'] = $mysql['is_manager'];
   $_SESSION['isadmin'] = $mysql['is_admin'];
   $_SESSION['sysadmin'] = $mysql['is_sysadmin'];

Thanks so much,

I added it a second ago to try it, and forgot to change the variables! Solved!

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.