markt97 Posted December 5, 2013 Share Posted December 5, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/284556-fatal-error-cannot-use-object-of-type-mysqli_result-as-array-in-help-please/ Share on other sites More sharing options...
Solution Ch0cu3r Posted December 5, 2013 Solution Share Posted December 5, 2013 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']; Quote Link to comment https://forums.phpfreaks.com/topic/284556-fatal-error-cannot-use-object-of-type-mysqli_result-as-array-in-help-please/#findComment-1461376 Share on other sites More sharing options...
markt97 Posted December 5, 2013 Author Share Posted December 5, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/284556-fatal-error-cannot-use-object-of-type-mysqli_result-as-array-in-help-please/#findComment-1461377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.