Hi Im trying to create a admin login. In my, mysql database, in the table 'users_table' I have the field admin and its default value = N but if it equals Y then direct it the Admin.php here is my current code for starting a new session and I was wondering if I could put it in there so that if it does = Y then say session 'Admin' starts and redirects to Admin.php instead of $_SESSION['name'] (btw 'name' is field 1 in my database and field 'admin' is 7
<?php
session_start();
include ('condb.php');
$name = $_POST ['username'];
echo $name;
$query ="SELECT name FROM users_table WHERE (name = '$name')" ;
$result = mysql_query($query)
or die (mysql_error($con));
$row= mysql_num_rows($result);
if ($row=1){
$_SESSION['name'] = $row[1];
}
?>
Apart from the obligatory SQL injection, what have you tried? This says "here is my code, fix it". Please read a (recent) PHP + MySQL tutorial, which will point you towards PDO. Really, give it a read.
In the meantime, something like this might work:
$rowcount = mysql_num_rows($result);
if ($rowcount == 1){
$row = mysql_fetch_array($result);
$_SESSION['name'] = $row['name'];
if ($row['admin'] == 'Y')
{
$_SESSION['admin'] = $row['admin'];
header("Location: admin.php");
exit();
}
}