Jump to content

Archived

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

markt97

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

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!

Share this post


Link to post
Share on other sites

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'];

Share this post


Link to post
Share on other sites

 

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!

Share this post


Link to post
Share on other sites

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