我正在尝试创建一个PHP注册和登录页面,但我的代码都没有工作。
我正在使用PHP7,而且我是PHP的新手。
Register.php:http://hastebin.com/kubuqesumo.xml
Login.php:http://hastebin.com/opevutixom.php
Config.php:http://hastebin.com/usaluvumed.php
错误:
警告:mysqli_real_escape_string()要求参数1为mysqli,第14行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_real_escape_string()要求参数1为mysqli,第15行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_real_escape_string()要求参数1为mysqli,第16行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_real_escape_string()期望参数1为mysqli,第17行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_real_escape_string()要求参数1为mysqli,第18行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_real_escape_string()期望参数1为mysqli,第19行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_real_escape_string()要求参数1为mysqli,第20行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出的字符串
警告:mysqli_query()需要至少2个参数,在第24行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出1
警告:mysqli_error()预计在第24行的C:\ xampp \ htdocs \ Application_Website \ register.php中给出1个参数,0
请帮助我,
谢谢,雅各布。
答案 0 :(得分:0)
嗯,mysqli::real_escape_string
是类成员mysqli
的程序样式。
PHP告诉您它希望第一个参数是config.php
对象。
这意味着您正在使用的函数是以过程风格编写的类方法,并且您在没有所需对象的情况下调用它们。
在$con = new mysqli("localhost","root","","app");
// Check connection
if ($con->connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$con->select_db("application");
// Wait a minute, the selected database should be the 4th parameter of the constructor, what is "app" and what is "application"?
//$con->close(); This should not be called before using the connection...
:
register.php
在mysqli_real_escape_string(...);
中你应该改变:
$con->real_escape_string(...);
使用:
mysqli_query()
同样适用于$con->query(...);
:
{{1}}
答案 1 :(得分:0)
查看mysqli_real_escape_string
的php文档以及您的错误,您似乎需要2个参数
string mysqli_real_escape_string ( mysqli $link , string $escapestr )
mysqli $link
是与mysql数据库的连接。
在http://php.net/manual/en/mysqli.real-escape-string.php上的示例中找到:
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
然后像您一样使用您的POST数据,或者如示例所示:
$city = $mysqli->real_escape_string($city);
答案 2 :(得分:0)