<?php
//start the session
mysql_connect("localhost","root","");
@mysql_select_db(fcs)
or die("Unable to select Database");
//check if the form has been submitted
if(isset($_POST['submit'])){
$msg="";
//VALIDATE form information
if(empty($_POST['uname'])){
$msg="Please enter your username.";
}
if(empty($_POST['upass'])){
$msg .="Please enter your password.";
}
//check length of password
if(strlen($_POST['upass']) > 6){
$msg .="Invalid password.";
}
if(empty($msg)){
$sql = "SELECT uname,upass FROM administrator WHERE user ='".$_POST['uname']."'";
$sql .= "AND password ='".md5($_POST['password'])."'";
if(!$res = mysql_query($sql)){
$msg.=mysql_error();
}else{
//user exists in system, set the session variables
if (mysql_num_rows($res) == 1) {
while($row = mysql_fetch_assoc($res)){
// the user name and password match,
$_SESSION['uname'] = $row['uname'];
$_SESSION['upass'] = $_POST['upass'];
//Now go to the main page
header('location../admin.php');
}
}else{
$msg = "Your login details did not match";
}//end numrows check
}//end res check
}
}//end submit check
?>
Примечание:
Я хочу загрузить страницу (admin.php), если имя пользователя и пароль были правильными, иначе
просто выведите сообщение: