我有一个名为admin(和密码admin)的用户的MySQL数据库。我用它来测试我的配置。当我点击登录时,没有任何反应。谁能看出我做错了什么?
以下是我的登录表单:
<form action="loginProcess.php" method="POST">
Username: <input type='text' name='username'></br>
<!-- input type password makes the password hidden as it is typed -->
Password: <input type='password' name='password'></br>
<input type='submit' value='Login'/>
</form>
</br>
</br>
<!-- Register New User -->
<form action="register.php" method="POST"> </br>
Not Registered?<input type='submit' value='Click Here To Register'/>
</form>
此表单将您带到此loginProcess.php文件:
<?php
ob_start();
session_start();
// Include database connection and select database UFPProducts
include "./shopdb/connection.php";
?>
<?php
//
// (2) Collect data from form and save in variables
// real escape string to protect from SQLi attacks
$username=mysql_real_escape_string(htmlentities($_POST['username']));
$password=mysql_real_escape_string(htmlentities($_POST['password']));
// (3) Create query of the form below to search the user table
// "SELECT * FROM Users WHERE UserName='$username' AND Password='$password'"
$query = "SELECT * FROM USERS where Username='$username' AND Password='$password'";
$result = mysql_query($query) or die (mysql_error());
// (3) Run query through connection
// (4) Check result of query using code below
// if rows found set authenticated user to the user name entered
if (mysql_num_rows($result) > 0) {
$_SESSION["authenticatedUser"] = $username;
// Relocate to the logged-in page
header("Location: ./login/loggedOn.php");
}
else
// login failed redirect back to login page with error message
{
$_SESSION["message"] = "Could not connect as $username " ;
header("Location: login.php");
}
?>
这是我的connection.php文件,只是有人想看:
<?php
//*** "die()" will exit the script and show an error if something goes wrong with the "connect" or "select" functions.
//*** A "mysql_connect()" error usually means your connection specific details are wrong
//*** A "mysql_select_db()" error usually means the database does not exist.
// Place db host name. Usually is "localhost" but sometimes a more direct string is needed
$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "root";
// Place the password for the MySQL database here
$db_pass = "";
// Place the name for the MySQL database here
$db_name = "UFPProducts";
$connect = mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error());
mysql_select_db("$db_name") or die("there is no database with that name");
// echo "<center>You are successfully connected to the Under5Pounds database.</center><br>";
?>
我现在没有收到任何错误消息,只要输入用户名+密码并点击登录就没有做任何事情。
答案 0 :(得分:0)
在loginProcess.php中尝试此代码
$username=$_POST['username'];
$密码= $ _ POST [ '密码'];
答案 1 :(得分:0)
我认为你应该删除 ob_start(); 从loginProcess.php文件的第一行开始,它没有任何关系(除非告诉我好的理由)并阻止要发送到浏览器的数据