Jump to content

[SOLVED] If statement problem


whiskedaway

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/115582-solved-if-statement-problem/
Share on other sites

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 />";
}

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 />";
}

?>

Archived

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

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