markt97 Posted December 5, 2013 Share Posted December 5, 2013 Hi, My if statement is not working for session variables, please help! Login page (Sets session): $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'] = $mysql2['first_name']; $_SESSION['lname'] = $mysql2['last_name']; $_SESSION['add1'] = $mysql2['address_1']; $_SESSION['add2'] = $mysql2['address_2']; $_SESSION['county'] = $mysql2['county']; $_SESSION['postcode'] = $mysql2['postcode']; $_SESSION['tel'] = $mysql2['tel_no']; $_SESSION['mobile'] = $mysql2['mobile_no']; $_SESSION['team'] = $mysql2['team']; $_SESSION['ismanager'] = $mysql2['is_manager']; $_SESSION['isadmin'] = $mysql2['is_admin']; $_SESSION['sysadmin'] = $mysql2['is_sysadmin']; Then on the profile page: <tr> <td class="profile_tab"> Is Team Manager?</td> <td class="profile_tab"><input style="text-align: center; font-size: 14pt;" type="text" value="<?PHP if($_SESSION['ismanager'] = "1") {echo "YES";} else {echo "NO";};?>" disabled size="50"></td> </tr> <tr> <td class="profile_tab"> Is Administrator?</td> <td class="profile_tab"><input style="text-align: center; font-size: 14pt;" type="text" value="<?PHP if($_SESSION['isadmin'] = "1") {echo "YES";} else {echo "NO";};?>" disabled size="50"></td> </tr> <tr> <td class="profile_tab"> Is System Administrator?</td> <td class="profile_tab"><input style="text-align: center; font-size: 14pt;" type="text" value="<?PHP if($_SESSION['sysadmin'] = "1") {echo "YES";} else {echo "NO";};?>" disabled size="50"></td> </tr> However the echo on the if statement doesn't work and just shows yes..... I have changed in DB my value of is admin to 0 and it still says yes on my profile page, Any help appreciated! Link to comment https://forums.phpfreaks.com/topic/284560-if-statement-not-working/ Share on other sites More sharing options...
AbraCadaver Posted December 5, 2013 Share Posted December 5, 2013 = is for assignment. Try using == in the if statements. You could also use: <?php echo $_SESSION['sysadmin'] ? "YES" : "NO"; ?> Link to comment https://forums.phpfreaks.com/topic/284560-if-statement-not-working/#findComment-1461390 Share on other sites More sharing options...
markt97 Posted December 5, 2013 Author Share Posted December 5, 2013 = is for assignment. Try using == in the if statements. Thanks, sorry it did work, forgot to log out and then in again! Link to comment https://forums.phpfreaks.com/topic/284560-if-statement-not-working/#findComment-1461391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.