顯示HTML代碼錯誤的憑據錯誤我有一個問題 這是我的index.php文件無法從PHP
<section class="main">
<form class="form-3" method="post" action="back/login.php">
<p class="clearfix">
<input type="text" name="username" id="username" placeholder="username">
<label for="login">username</label>
</p>
<p class="clearfix">
<input type="password" name="password" id="password" placeholder="password">
<label for="password">password</label>
</p>
<p class="clearfix">
<input type="submit" name="submit" value="Sign In">
</p>
<p class="clearfix">
<label for="remember">remember me</label>
<input type="checkbox" name="remember" id="remember">
</p>
</form>
*
<div class="error"><?php echo $error;?></div>
*
</section>
,這是我的login.php文件
<?php
session_start();
include("connection.php");
$error = "";
if (isset($_POST["submit"])) {
if (empty($_POST["username"]) || empty($_POST["password"]))
$error = "Both fields are required.";
else {
$username = $_POST['username'];
$password = $_POST['password'];
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($db, $username);
$password = mysqli_real_escape_string($db, $password);
$password = md5($password);
$sql = "SELECT uid FROM users WHERE username='$username' and password='$password'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$login_user = $username;
if (mysqli_num_rows($result) == 1) {
$_SESSION['username'] = $login_user;
header("location: home.php");
}
else {
$error = "Incorrect username or password.";
header("location: ../index.php");
}
}
}
但我的$在HTML代碼錯誤不起作用...
我的意思是,當我把不正確的密碼和用戶名,它只是重定向我的index.php頁面,裏面沒有任何錯誤...
也是我的login.php文件包含在我的index.php
http://php.net/manual/en/function.error-reporting.php –
http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent- php中的錯誤 –
它們是兩個單獨的文件 - 您在其中設置的變量在另一個文件中不可用。更好的是會話變量或包含查詢字符串在您的頭()fnction可能 – RamRaider