whiskedaway Posted July 19, 2008 Share Posted July 19, 2008 Hi everyone! I was hoping you might be able to pick up what I've done wrong. $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql3 = "SELECT status FROM members WHERE username = '$_POST[fusername]'"; $result3 = mysqli_query($cxn, $sql3) or die ("Couldn't execute query 3."); if ($result3 == "Super Administrator") { $message = "Super Admin.<br />"; } else { $message = "You do not have permission to post comments.<br />"; } Even when the status of the user is "Super Administrator", it is skipping the if bracket and going straight to the else. So I think there's a problem, probably with the way I'm calling $result3 in the if statement. If anyone can help, it would be greatly appreciated. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/ Share on other sites More sharing options...
wildteen88 Posted July 19, 2008 Share Posted July 19, 2008 $result3 is a result resource from the mysql query. You need to use mysqli_fetch_assoc in order to get the data retrieved from the query. Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594182 Share on other sites More sharing options...
whiskedaway Posted July 20, 2008 Author Share Posted July 20, 2008 Thanks, I forgot that statement. *headdesk* However, it's still not working. Here's the updated code: $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $sql3 = "SELECT status FROM members WHERE username = '$_POST[fusername]'"; $result3 = mysqli_query($cxn, $sql3) or die ("Couldn't execute query 3."); $staff = mysqli_fetch_assoc($result3); if ($staff == "Super Administrator") { $message = "Super Admin.<br />"; } else { $message = "You do not have permission to post comments.<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594497 Share on other sites More sharing options...
MasterACE14 Posted July 20, 2008 Share Posted July 20, 2008 $result3 = mysqli_query($cxn, $sql3) or die ("Couldn't execute query 3."); $staff = mysqli_fetch_assoc($result3); $staff = $staff['status']; Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594500 Share on other sites More sharing options...
whiskedaway Posted July 20, 2008 Author Share Posted July 20, 2008 It's still not working. Oh and I queried the database just to make sure it was actually returning "Super Administrator", and it is. So it's a problem with the code. Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594507 Share on other sites More sharing options...
Btown2 Posted July 20, 2008 Share Posted July 20, 2008 try this... $status = mysql_fetch_array($result3) or die(mysql_error()); if($status[0] == "Super Administrator") Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594510 Share on other sites More sharing options...
whiskedaway Posted July 20, 2008 Author Share Posted July 20, 2008 There's a problem with that statement: $staff = mysqli_fetch_array($result3) or die("Couldn't execute fetch array"); if ($staff[0] == "Super Administrator") { It brings up "Couldn't execute fetch array". Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594515 Share on other sites More sharing options...
MadTechie Posted July 20, 2008 Share Posted July 20, 2008 try this <?php $cxn = mysqli_connect($host, $user, $password, $dbname) or die ("Connection failed."); $fusername= $mysqli_real_escape_string($_POST['fusername']); //stop SQL injection $sql3 = "SELECT status FROM members WHERE username = '$fusername' "; $result3 = mysqli_query($cxn, $sql3)or die ("Couldn't execute query 3."); $staff = mysqli_fetch_assoc($result3); if ($staff['status'] == "Super Administrator") { $message = "Super Admin.<br />"; }else { $message = "You do not have permission to post comments.<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594527 Share on other sites More sharing options...
whiskedaway Posted July 20, 2008 Author Share Posted July 20, 2008 That worked! Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594531 Share on other sites More sharing options...
MadTechie Posted July 20, 2008 Share Posted July 20, 2008 welcome, can you click topic solved please (bottom right) Quote Link to comment https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/#findComment-594535 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.