Jump to content

[SOLVED] If ...... is equal to ....... or ......... or ........... or HELP


Akenatehm

Recommended Posts

Hey Guys,

 

Just need to know if this is the right way to things:

$getuserpriviliges = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error());
if($getuserpriviliges == 'Owner' || 'Admin' || 'Owner/Admin' || 'Administrator')
{
//Execute this Code
}

Link to comment
Share on other sites

It is not

 

$result = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($result);
$getuserpriviliges = $row['rank'];
if($getuserpriviliges == 'Owner' || $getuserpriviliges =='Admin' || $getuserpriviliges =='Owner/Admin' || $getuserpriviliges =='Administrator')
{
//Execute this Code
}

 

alternatively

 

if(in_array($getuserpriviliges, array("Owner","Admin","Owner/Admin","Administrator"))) {
//Execute this Code
}

Link to comment
Share on other sites

I'll second that -

 

You will find that only code similar to what Mchl posted will actually work because you need to fetch the row from the result set and reference the value that the query returned.

 

The code you are apparently using will match anything as long as the query did not fail. Try it for an account that is not an 'Owner', 'Admin', 'Owner/Admin' or 'Administrator.

Link to comment
Share on other sites

Thanks plutomed. Works fine. Much appreciated!

 

That code will not work I'm afraid. read the previous replies.

 

Ok, now they both are only showing Read More, even when I am logged in.

 

How can I make it work?

 

Mchl posted an example several replies ago.

Link to comment
Share on other sites

Ok this is what I have:

 

<?php
$getuserpriviliges = mysql_query("SELECT rank FROM users WHERE username = '$username'") or die(mysql_error());

if(in_array($getuserpriviliges, array("Owner","Admin","Owner/Admin","Administrator"))) 
{
echo '<a class="readmore"href=\"read_more.php?newsid=$id\">Read More</a>';
echo '<a class="readmore"href=\"edit_news.php?newsid=$id\">Edit</a>';
echo '<a class="readmore"href=\"edit_news.php?newsid=$id\">Delete</a></p> </div>';

} 
else
{
  echo '<a class="readmore"href=\"read_more.php?newsid=$id\">Read More</a></p> </div>';
}
}
}
?>

 

Mchls solution did not seem to work.

Link to comment
Share on other sites

Your missing any call to mysql_fetch_assoc. As I said several replies ago, $getuserpriviliges is a result resource, now your treating it as an array.

 

Theres a tutorial on our main site that covers basic database operations, you should read it.

 

I did have it in there. But I removed it because I thought it wasn't working (the real reason was because i didnt have my rank "Owner" in the Database). I added that all in and its all working fine.

 

Thanks GUys.

 

 

 

Link to comment
Share on other sites

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.