I am just trying to write login system for an php app. I need to user log type by type (Admin/User dashboard), i don´t see any reason why this shouldn´t work. I will be really glad if someone help me. Thanks you so much. The problem is, that when u try to log in, with proper username and password, even if its correct, it just throw out "Wrong username or pw...."
<?php
session_start();
$host="127.0.0.1"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="rocketevents"; // Database name
$tbl_name="users"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['myusername'];
$mypassword=($_POST['mypassword']);
$type='';
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM $tbl_name WHERE `Username`= '$myusername' and `Password`= '$mypassword' and `Type`= '$type'";
$result = mysql_query($sql);
$array = mysql_fetch_array($result);
$_SESSION['myusername']=$array['myusername'];
$_SESSION['mypassword']=$array['mypassword'];
$user_type = $array['Type'];
$count=mysql_num_rows($result);
if (empty($_POST['myusername']) or (empty($_POST['mypassword']))){
echo"Please fill in your username or password";
echo"<br>Please try to <a href='index.php'>Log in </a> again";
} else {
if ($count == 1) {
$_SESSION ['myusername'] = $myusername;
$_SESSION ['mypassword'] = $mypassword;
if ($user_type == "Admin") {
header ( "location: admin.php" );
} else if ($array ["type"] == "User") {
header ( "location: user.php" );
} else if ($array ["type"] == "Visitor") {
header ( "location: visitor.php" );
}
}
else {
include("index.php");
echo"Wrong user or password";
echo"<br>Please try to <a href='index.php'>Log in</a> again or go to <a href='sign.php'>registration</a> page";
}
}
?>