Hey everyone,
I have a login script that works but I want to add some code to it that includes the field labeled “user_level” in my database to determine whether or not the user is an admin or not…“1” for the admin and “o” for regular user. If the user is an admin, they will be redirected to the admin page, and if not, then they will be redirected to the regular user page.
here is the checkuser.php file for the login page
[php]<?php
session_start();
$host=“"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="****”; // Table name
// Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);
// username and password sent from form
$username=$_POST[‘username’];
$password=$_POST[‘password’];
// To protect MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql=“SELECT * FROM users WHERE username=’$username’ AND password=’$password’ AND activated=‘0’”;
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==0){
// Register $myusername, $mypassword and redirect to file “login_success.php”
$_SESSION[‘username’] = $username;
$_SESSION[‘password’] = $password;
header(“location: user-area.php”);
}
else {
echo “Wrong Username or Password”;
}
?>[/php]
How would I achieve this? do I simply just and another sql statement in and if so how would I write it so it doesn’t interfere with what I have already written? Any help would be greatly appreciated