我正在尝试使用php将登录门户连接到mysql,但是我的index.php没有重定向到profile.php,并且显示带有空白屏幕的index.php是我的代码文件。数据库已正确添加。
的login.php
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit']))
{
if (empty($_POST['username']) || empty($_POST['password']))
{
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
$connection = mysql_connect("localhost", "root", "pwd");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("company", $connection);
$query = mysql_query('select * from login where password="$password" AND username="$username"', $connection);
$rows = mysql_num_rows($query);
if ($rows == 1)
{
$_SESSION['login_user']=$username; // Initializing Session
header("location: profile.php"); // Redirecting To Other Page
exit();
}
else
{
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>
的index.php
<?php
include('login.php'); // Includes Login Script
if(isset($_SESSION['login_user']))
{
header("location: profile.php");
exit();
}
?>
<!DOCTYPE html>
//some html code
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>