Jump to content

Need help please!


iTech
Go to solution Solved by adam_bray,

Recommended Posts

Hello I need help concerning my code. I can't figure out how, if the user has logged in with the usertype as "admin". If so they should see a link if not then they are normal user.

 

Here is an image of the database

post-168659-0-17261400-1398586805_thumb.png

 

here is my code:

$queryget = mysql_query("SELECT usertype FROM tbl_usernames") or die ("Query failed.");
$row = mysql_fetch_assoc($queryget);

if($_SESSION['username']= $row['usertype'] == "admin")
{
	echo "<p><a href='create_user.php'>Create a new user</a></p>";
}
else
{
	echo "You are a normal user.";
}
Link to comment
Share on other sites

  • Solution

Your code and database are really insecure, and you should use mysqli_* instead of mysql_* functions.

 

This should work -

<?php

	$user = mysql_real_escape_string($_SESSION['username']);
	
	$queryget = mysql_query('SELECT usertype FROM tbl_usernames WHERE user = \''.$user.'\' LIMIT 1;') or die ('Query failed. ' . mysql_error());
	$row = mysql_fetch_assoc($queryget);
	
	if($row['usertype'] == 'admin')
	{
		echo '<p><a href="create_user.php">Create a new user</a></p>';
	}
	else
	{
		echo 'You are a normal user.';
	}

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