我的登录页面有一个php文件。连接的html页面上的表单中的用户名和密码都在数据库中,但是当我单击提交时,我得到了连接重置错误页面。我错过了什么?这是在netbeans中进行的,我使用的是mysql服务器和apache web服务器。这也是一个附加的注销选项,选择它只会导致浏览器提示如何处理它(保存或打开)。我已经尝试将userId和passID的值更改为数据库中的值,但它仍然无效。我究竟做错了什么?在一些移动文件后我得到了下面的消息。
警告:mysqli_real_escape_string()期望参数1为mysqli,第14行的C:\ WampDeveloper \ Websites \ DefaultWebsite \ webroot \ Loginpage.php中给出的字符串警告:mysqli_real_escape_string()期望参数1为mysqli,字符串在第15行的C:\ WampDeveloper \ Websites \ DefaultWebsite \ webroot \ Loginpage.php Acess否认
<?php
session_start();
include("dbconfig.php");
$dbname="sailingdb";
$errorvar = "";
if (isset($_POST['submit'])) {
if (empty($_POST['user']) || empty($_POST["pass"])) {
$errorvar = "Both field are required";
} else {
//defining and injection protecting data
$userID=$_POST['user'];
$passID=$_POST["pass"];
$userID=stripslashes($userID);
$passID=stripslashes($passID);
$userID=mysqli_real_escape_string($dbname, $userID);
$passID=mysqli_real_escape_string($dbname, $passID);
$passID=md5($passID);
$query = "SELECT * FROM users where userName = '$userID' AND pass = '$passID'";
$queryresult=mysqli_query($dbname,$query);
$row = mysqli_fetch_array($queryresult,MYSQLI_ASSOC);
if (mysqli_num_rows($queryresult)==1) {
$_SESSION['userName'] = $userID;
header("MainMenu.html");
} else {
header("MainMenu.html");
echo "Acess denied";
}
}
}
?>
dbconfig.php代码如下所示。
<?php
$servername="localhost";
$user="root";
$passw="*****";
$dbname="Sailingdb";
$conn=new mysqli($servername, $user, $passw, $dbname);
if (mysqli_connect_error()) {
die("Databse connection failed: " . mysqli_connect_error());
}
?>
答案 0 :(得分:0)
消息说:
mysqli_real_escape_string()期望参数1为mysqli,string 给出
因为你在dbconfig.php中有这个:
$conn=new mysqli($servername, $user, $passw, $dbname);
您可以尝试这样做:
$userID=mysqli_real_escape_string($conn, $userID);
$passID=mysqli_real_escape_string($conn, $passID);