所以,我有以下代码,它应该用作登录系统。当我输入应该输入的详细信息时,它仍然会出现“错误的详细信息。请再试一次”。这可能是一个愚蠢的基本错误,但我还不熟悉PHP。
<?php
$dbc = mysqli_connect("hostaddress","user","pass") or
die("Could not connect to server". mysqli_connect_error());
mysqli_select_db($dbc, "dbname") or die("could not connect to the database");
//Check if the login form has been submitted;
if(isset($_POST["go"])) {
$addr = mysqli_real_escape_string($dbc, htmlentities($_POST["e_address"]));
$psw = SHA1 ($_POST["u_pass"]); //Using sha1() to encrypt passwords
//query to check if the email address and password match;
$q = "SELECT * FROM users WHERE address='$addr' AND pass='$psw'";
//run the query and store result;
$res = mysqli_query($dbc, $q);
//Make sure we have a positive result;
if($res = mysqli_query($dbc, $q)) {
//Start a session;
session_start();
//Creating a log session variable that will persist through pages;
$_SESSION["log"] = "in";
//Redirecting to restricted page;
header("location: restricted.php");
} else {
//Create an error message;
$error = "Wrong details. Please try again";
}
} //End isset go
?>
<form method="post" action="#">
<p><label for="e_address">Email Address:</label></p>
<p><input type="text" name="e_address" value="" placeholder="Email Address" maxlength="30"></p>
<p><label for="u_pass">Password:</label></p>
<p><input type="password" name="u_pass" value="" placeholder="Password" maxlength="12"></p>
<p><button type="submit" name="go">Log me in</button></p>
</form>
<!-- Error Displayer -->
<p><strong><?php if(isset($error)) { echo $error; } ?></strong></p>
答案 0 :(得分:0)
尝试从第一行的session_start();
开始
并在查询or die(__LINE__." ".mysqli_error($dbc))
和U可以使用没有密码的查询,然后使用php
检查密码