0

Hye guys, can help me I have a problem with my login. At my login page user have to insert username and password. If the username and password has been set to staff it will direct to mainpage.php but if the username and password was on admin it will direct to mainpage_m.php I have try but not succesful.

This was my coding

<?php
session_start();

<!Doctype HTML>

<title>Login page</title>

<form Action="loginh.php" method="post">
<body background="pharmacy.jpg" bgcolor="#333333">
<br>
<div align="middle">
<img src="test.gif" alt="Smiley face" width="500" height="100" style="vertical-align:middle">
</div>
<br>
<body>
<Table align="center" border="1">
<tr><td bgcolor="white">Username</td>

<td><input type="textbox" name="username" required></td>
</tr>

<tr>
<td bgcolor="white">Password</td>
<td><input type="password" name="password" required></td>
</tr>

<tr colspan="3">
<td><input type="submit" name="Submit" value="submit"></td>
</tr>
</table>
<br>
</FORM>

<table align="center" border="5" bgcolor="white" bordercolor="red">
<tr colspan="2">
<td><p>New User? Please Register</p>
<FORM METHOD="LINK" ACTION="reg.php">
<div align="center"><INPUT TYPE="submit" align="middle" VALUE="NEW REGISTRATION"></div>
</FORM>
</td>
</tr>
</table>
<br>

<table align="center" border="3" bgcolor="white" bordercolor="red">
<td>
<p align="center">
Contact US<br>
It Department Al-Chemists<br>
Bangunan Wira Bakti<br>
088-7881345<br>
al_it@yahoo.com

</p>

<center><?php
date_default_timezone_set('Asia/Kuala_Lumpur');
echo date('Y-m-d H:i:s');
?>

1
Contributor
1
Reply
5
Views
3 Years
Discussion Span
Last Post by yong.roni
0

Handler for the file

<?php
session_start();

require "cn.php";

$user=$_POST['username'];
$pass=$_POST['password'];

$query=mysql_query("select * from reg where user='$user'");
$fetch=mysql_fetch_object($query);

if ($fetch->usertype == "admin")
{  $_SESSION['user']=$fetch->username;
   $_session['pass']=$fetch->password;
      $_SESSION['CurrentUser']=$user;
      $_SESSION['Currentid']=$id;

  header("location: mainpage_m.php");

   }
if($fetch->usertype =="staff" )
{  $_SESSION['user']=$fetch->user;
   $_session['pass']=$fetch->password;
     $_SESSION['CurrentUser']=$user;

   header("location: mainpage.php");

}else
{
  echo "Invalid data";
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.