Link to home
Create AccountLog in
Avatar of tankergoblin

asked on

identified account type


I have a login page. The page has user name and password textbox. After user
key-in the user name and password, user can press login button.

The system start do validation.

Now my problem stuck here.

my user has 2 different account type named user and admin

after user key in the user name and password. i want system to identified
user is under which account type and then redirect to the given page.

I have try this but failed.

My code is as below:

 $query = "select accountType from $this->dbUserTableLogin where username = \"$myusername\" and password = \"$mypassword\"";
	 $result = mysql_query($query);
	 if(!$result) die("Query didn't work. " . mysql_error());
         $count = mysql_num_rows($result);
       	while ($rows = mysql_fetch_array($result)) {		
	if($rows['accountType'] == user){
		$_SESSION["username"]=$myusername ; 
 		header("location:User Menu.php");

Open in new window

Above "if($rows['accountType'] == user){"
i received message: "Notice: Use of undefined constant user - assumed 'user'.."

but if i put '' on the code as below
"if($rows['accountType'] == 'user'){"
then i will not received the message but the codition become false.
In fact it is user = user.

Any idea?
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

Link to home
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
echo out both values:

echo $rows['accountType'] ."<br />";
echo "user <br />";
echo ($rows['accountType']=="user")?"True":"False";
echo "<br />";

Open in new window

you should get:

$count = mysql_num_rows($result);

while ($rows = mysql_fetch_array($result)) {      
my user has 2 different account type named user and admin
This would be a column in your data base table of users, just like the user-id and the password.  Just add the column, select it, and make your program logic dependent on the contents of the column.

The general design of PHP client authentication is shown in this article.  Add a column to the table definition for any additional information you want to carry about the user - permissions, email addresses, etc.