Im trying to create a members area and an admin area for my site. I have a form which asks for email/password then either redirects the user (if they are in the Members table to either the Admin section (if the type is 0) or simply back to the index.php (if the type is 1) and back to login.php if they dont sign in… Heres my logic
<?php
session_start();
include("db/configPDO.php");
// Define $myusername and $mypassword
$Email=$_POST['email'];
$Password=$_POST['password'];
// We Will prepare SQL Query
$STM = $dbh->prepare("SELECT type FROM Members WHERE email = :Email AND password = :Password");
// bind paramenters, Named paramenters alaways start with colon(:)
$STM->bindParam(':Email', $Email);
$STM->bindParam(':Password', $Password);
// For Executing prepared statement we will use below function
$STM->execute();
// Count no. of records
$count = $STM->rowCount();
//just fetch. only gets one row. So no foreach loop needed :D
$row = $STM -> fetch();
// User Redirect Conditions will go here
if(($count==1) && ($row==0))
{
$_SESSION[type]=$row[0];
$_SESSION[email]=$Email;
header( "location:Admin/");
}
else if (($count==1) && ($row==1))
{
$_SESSION[type]=$row[0];
$_SESSION[email]=$Email;
header( "location:index.php");
}
else
{
header("location:login.php");
}
// Closing MySQL database connection
$dbh = null;
?>
this is using the PDO thing so I’m not too sure.