php - if-else statement not working correctly in while loop

248

Solution:

I can't see any query which make the difference b/w admin and member, your code simply retrieving admin column and going through every value and printing the link whenever it matches.

Don't you think your query would be something like with a unique key plus you need to only check once instead of while loop

$query="SELECT admin FROM `$table_members` where id='uniqueid'";

or

$query="SELECT admin FROM `$table_members` where userID_email='uniqueid'";
$result=mysqli_query($connect, $query);
$row_cnt = mysqli_num_rows($result); // see if match found
if($row_cnt>0) { // if false mean unknown user
   $row=mysqli_fetch_assoc($result);
    $admin = $row['admin'];
    if ($admin=="Administrator") {
        echo "<a href=\"admin.php\">Admin Panel</a>";
    }
    else {
        echo "";
    }
}
96

Answer

Solution:

First of all your connection is problem

1)remove all double quotes in mysqli_connection parameters .your passing variable as parameter if you give double quotes it treated as string so remove double quotes

    $connect=mysqli_connect($db_server, $db_user, $db_password, $db_database);
    $query="SELECT admin FROM `$table_members` where email='user email address' ";
    $result=mysqli_query($connect, $query);
    while ($row=mysqli_fetch_assoc($result)) {
        $admin = $row['admin'];
        if ($admin=="Administrator") {
            echo "<a href=\"admin.php\">Admin Panel</a>";
        }
        else {
            echo "";
        }
    }

People are also looking for solutions to the problem: mysql - How to Get data that been clicked into next page in php?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.