I have this php login script which contain three users (Root, Secretary and Accountant) which does perfectly.
But as u can see every account has its php tag to allow certain user to login, My aim is to use only one PHP tag
<?php ....?>
for both account,Example (the login must check if username or password is not correct he/she will be directed to the same login page and the message will be "insert correct username or passord" with red text color ) and Also I'w like to introduce PHP login session so that if user is not Loged in, he/she will be directed to login page(index.php),I want to avoid user who try to bypass the system.
Any help please, am just new in php
This the codes
<?php
// Connect to server and select databse.
$link=mysql_connect("localhost","root", "mcl")or die("cannot connect");
mysql_select_db("mcl",$link)or die("cannot select DB");
$sql="SELECT * FROM admin WHERE fname=('$_POST[fname]') and
password=('$_POST[password]')";
$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"
header("location:dashboard.php");
}
?>
<?php
$fname="fname";
$link=mysql_connect("localhost","root", "mcl")or die("cannot connect");
mysql_select_db("mcl",$link)or die("cannot select DB");
$sql="SELECT * FROM acco_untant WHERE fname=('$_POST[fname]') and
password=('$_POST[password]')";
$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"
header("location:dash_accou.htm");
}
else {
echo "Invalid username or password <a href=index.php><input name=Click here to reload
type=button
disabled value= <<<Reload>";
}
?>
<?php
// Connect to server and select databse.
$link=mysql_connect("localhost","root", "mcl")or die("cannot connect");
mysql_select_db("mcl",$link)or die("cannot select DB");
$sql="SELECT * FROM secretary WHERE fname=('$_POST[fname]') and
password=('$_POST[password]')";
$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"
header("location:dash_secretary.htm");
}
?>