Jump to content

Need help please!


iTech

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
https://forums.phpfreaks.com/topic/288056-need-help-please/
Share on other sites

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
https://forums.phpfreaks.com/topic/288056-need-help-please/#findComment-1477430
Share on other sites

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.