-1

我有一个 MySQL 数据库,用户名为 admin(和密码 admin)。我正在使用它来测试我的配置。当我点击登录时,什么也没有发生。谁能看看我是否做错了什么?

这是我的登录表格:

    <form action="loginProcess.php" method="POST">
    Username: <input type='text' name='username'></br>

    <!-- input type password makes the password hidden as it is typed -->
    &nbsp;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>";
?>

我现在没有收到任何错误消息,一旦我输入用户名+密码并单击登录,它就不会做任何事情。

4

2 回答 2

0

在 loginProcess.php 中尝试此代码

$username=$_POST['username'];

$password=$_POST['密码'];

于 2012-11-17T12:17:27.837 回答
0

我认为你应该删除 ob_start(); 从 loginProcess.php 文件的第一行开始,它与那里无关(除非告诉我充分的理由),它阻止数据发送到浏览器

于 2012-11-17T12:18:12.373 回答