Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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