谁能告诉我为什么这个简单的 PHP/MySQL 登录代码总是显示“错误的用户名或密码”,即使我输入了正确的用户名/密码组合?我花了很多时间试图弄清楚这一点。
<?php
// Database Connection
mysql_connect("IP", "charlesfries", "Password") or die(mysql_error());
mysql_select_db("charlesfriessdatabase") or die(mysql_error());
// Variables
$username = $_POST["username"];
$password = $_POST["password"];
$result = mysql_query("SELECT * FROM accounts WHERE username = '$username' and password = '$password'");
// Success
$count = mysql_num_rows($result);
if ($count == 1) // Checks for Single Record of Given Username & Password
{
session_register("username"); // Registers Username Key in Session
session_register("password"); // Registers Password Key in Session
header("location:http://charliefries.tk/");
}
// Failure
else
{
echo "Wrong Username or Password";
}
?>
另外,请不要告诉我我的代码是可注入的。我知道它是。
这是我的表单代码:
<form action="signinprocess.php" method="post"> <!-- Sign In Process -->
Username: <input type="text" name="username" style="width:150">
<br />
Password: <input type="password" name="password" style="width:153">
<br />
<br />
<input type="submit" value="Sign In">
</form>