Okay, i am making a script for my computer business so we can check customer system information that we have stored in the mysql database on the go and check warranty info and all that good stuff. I am the owner, i want administrative access, and i want my techs to only be able to do certain things. So i made the file login_success.php for my techs and admin_menu.php for me. I have a file checklogin.php which does just what the name says. The database is setup with id, username, password, and admin. I need to make it so if admin=1, then display the admin_menu.php but if admin=0, then display login_success.php. Here is my current coding.
<?php
$host="Hidden for privacy reasons"; // Host name
$dbusername="Hidden for privacy reasons"; // Mysql username
$dbpassword="Hidden for privacy reasons"; // Mysql password
$db_name="Hidden for privacy reasons"; // Database name
$tbl_name="Hidden for privacy reasons"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$dbusername", "$dbpassword")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 (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
// Register $username, $password and redirect to file "login_success.php"
session_register("username");
session_register("password");
header("location:login_success.php");
}
else {
echo "You have entered an invalid technician ID. Please try again.";
}
?>
How do i add that function to this script at the end so it displays the proper tech/admin page? Please help me, im in a rut. Im not a pro coder, just a newbie playing around. Thank you so much in advance!
MOD EDIT: [noparse]
..
[/noparse] bbcode tags added; please use these in the future when posting PHP code.