Código HTML:
<form action="login_check.php" method="post" class="form"> <label>UserName :</label> <input id="name" name="username" placeholder="username" type="text"> <label>Password :</label> <input id="password" name="password" placeholder="**********" type="password"> <input name="submit" type="submit" value="login"> <span><?php echo $error; ?></span> </form>
Código PHP:
<?php
include_once "conexion.php";
session_start();
$error='';
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Usuario o Contraseña invalida.";
}
else
{
$username=$_POST['username'];
$password=$_POST['password'];
$username = stripslashes($username);
$password = stripslashes($password);
$query = mysql_query("select * from registration where password='$password' AND username='$username'", $con);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username;
$fila=mysql_fetch_array($query);
if($fila['tipousuario']=='admin') {
header("Location: index_a.php");
exit;
}
else {
header("Location: index_c.php");
exit;
}
} else {
$error = "Usuario o Contraseña invalida.";
}
mysql_close($con);
}
}
?>