Jump to content

[SOLVED] Simple if/mysql question!


Guernica

Recommended Posts

I have a premium section of my site I am making. And I only want people with a value of "2" in the usergroup column to be able to view it. So on the pages what would I use for a code? I am pretty clueless at this part.

 

Would it be like...

 

$query = ...

$result = ...

$row = ...

 

if($usergroup == 2) {

  echo "...";

}

 

...

 

I have no idea where to start lol. Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/58947-solved-simple-ifmysql-question/
Share on other sites

You've pretty much explained it right yourself. Pull the user's level from the table and check it.

 

If it equals 2 (which is what you want to allow) then show the page.

 

What I would add though is maybe redirecting the user to a different page if the value isn't equal to 2.

<?php
  if ($usergroup==2) {
    //right value, show the page
  } else {
    header("Location: index.php");
    exit;
  }
?>

 

That way if the user doesn't have value 2 then they're redirected to index.php instead.

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.