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

Link to comment
Share on other sites

I dont think it recognizes the variable $usergroup. I have:

 

FIXED

 

And I set my usegroup # to 2, and it still does the else echo of- Usergroup: 1.

 

edit: I got it. :D Forgot to make a

$usergroup = $row['usergroup'];

 

thanks!

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.