My page works, in the sense that login will take me to index.php, but it will never re-direct to dashboard.php. I appreciate any input.
Database columns are: id | username | password | admin
There are only two types of account, the admin account is indicated by a 1
<?php
// Get username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// Connect to database
include "db_connect_service.php";
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$mypassword = crypt($mypassword, '$1$philipphp');
// Query
$result= $dbh->query("SELECT * FROM members WHERE username='$myusername' AND password='$mypassword';");
// Mysql_num_row is counting table row
$count = $result->rowCount();
// Determine if user is "user" or "admin"
$usertype = $dbh->query("SELECT admin FROM members WHERE username='$myusername';");
$row = mysql_fetch_row($usertype);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1) {
// Start session, register $myusername, $mypassword and redirect to login_success.php
session_start();
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
$_SESSION['admin'] = $row;
// Redirect to appropriate page depending on user rights. Indicator 0 for user, 1 for admin.
if ($_SESSION['admin'] == 1){
header("location:dashboard.php");
}
else {
header("location:index.php");
}
$dbh = null;
}
else {
echo "Wrong Username or Password";
}
?>