下工作,我想提出一個登錄頁面,HTML部分是:登錄腳本只特定條件
<form action="login.php" method="post">
Email: <input type="email" placeholder="Email" name="email">
Password: <input type="password" placeholder="Password" name="password">
<input name="submit" type="submit" value=" Login ">
</form>
而且login.php中頁面
<?php
if (isset($_POST['submit']))
{
if (empty($_POST['email']) || empty($_POST['password']))
{
$error = "email or Password is invalid";
}
else
{
// Define $email and $password
$email=$_POST['email'];
$password=$_POST['password'];
// To protect mysqli injection for Security purpose
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysqli_real_escape_string($email);
$password = mysqli_real_escape_string($password);
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysqli_connect("abc.com", "abc", "123");
// Selecting Database
$db = mysqli_select_db("dealapp", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysqli_query("select * from users where password='$password' AND email='$email'", $connection);
$rows = mysqli_num_rows($query);
if ($rows == 1)
{
$_SESSION['login_user']=$email; // Initializing Session
header("location: index.html"); // Redirecting To Other Page
}
else
{
$error = "email or Password is invalid";
}
mysqli_close($connection); // Closing Connection
}
}
?>
有跡象表明,我的兩個問題面臨:
1)當我使用striplashes
和mysql_real_escape_string
,該程序顯示以下錯誤,我無法進行數據庫連接。但如果我刪除它們,那麼它運行正常。我無法理解爲什麼會發生這種情況。
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/10/10898710/html/dealapp/admin/login.php
2)我的第二個問題是,我想如果用戶輸入一個錯誤的電子郵件/密碼重定向的頁面,但也不是當我使用重定向代碼,它被重定向,也不是顯示錯誤消息我已經嘗試了上面的代碼。然而,當登錄細節是真實的,然後它完美地工作。
任何幫助/指導,將不勝感激。
PS-我現在所做的更改和使用SQLI,但STIL它顯示錯誤
作爲一個便箋,你需要考慮'PDO'或'MySQLi'而不是'mysql_'函數,因爲它們已被棄用且已過時 – 2014-08-27 10:14:54