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
https://forums.phpfreaks.com/topic/149446-solved-if-is-equal-to-or-or-or-help/
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
}

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.

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.

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.

 

 

 

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.