Link to home
Create AccountLog in
Avatar of tankergoblin
tankergoblin

asked on

identified account type

Hi,

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);
		
	 if($count==1){    
       		
       	while ($rows = mysql_fetch_array($result)) {		
	if($rows['accountType'] == user){
		$_SESSION["username"]=$myusername ; 
 		header("location:User Menu.php");
		}}}else
....

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?
ASKER CERTIFIED SOLUTION
Avatar of sivagnanam chandrakanth
sivagnanam chandrakanth
Flag of India image

Link to home
membership
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:

user
user
True
$count = mysql_num_rows($result);
var_dump($count);

while ($rows = mysql_fetch_array($result)) {      
var_dump($rows);
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.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html