我在PHP升級時遇到了一些問題。之前,我使用PHP 5.2.0及以下版本;現在我已經升級到PHP 5.5.0。我的一些片段沒有按我的預期運行。升級後我不能使用mysql_ *函數PHP
這裏是一個,例如。它說,
Deprecated: mysql_real_escape_string()
我試圖mysqli_real_escape_string()
並得到了另一個錯誤:
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in
這裏是我的代碼:
<?php
require_once("includes/session.php");
require_once("connections/connection.php");
require_once("includes/functions.php");
?>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
//$hashed_password= md5($password);
?>
<!--Receive username password and authenticate whether the same or not with database one. -->
<?php
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($username);
$password = mysqli_real_escape_string($password);
?>
<?php
$query = "SELECT *
FROM login
WHERE username = '{$username}'
AND password = '{$password}'
AND status=1";
$result = mysql_query($query);
$count = mysql_num_rows($result);
if($count == 1){
//for the session
$result_fetch= mysql_fetch_array($result);
$_SESSION['user_id']= $result_fetch['id'];
$_SESSION['user_name']= $result_fetch['username'];
session_register("username");
session_register("password");
header("Location: dashboard.php");
exit;
}
else{
echo "The username or password is incorrect.";
}
?>
<?php
//5.Close connection
if(isset($connection)){
mysql_close($connection);
}
?>
請將該列表下降到有問題的行,或者至少突出顯示您遇到問題。 – 2014-10-10 12:36:04
你的第一個問題是使用mysql_ *函數。 – 2014-10-10 12:37:49
你在哪裏使用mysqli_real_escape_string()? – 2014-10-10 12:38:25