PHP失败了register.php

时间:2016-05-20 15:36:44

标签: php mysqli

我正在尝试创建一个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

请帮助我,

谢谢,雅各布。

3 个答案:

答案 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)

对于第14-20行,当您使用mysql_real_escape_string时,您正在使用mysqli_real_escape_string

mysql_real_escape_string在PHP 5.5中被弃用,并在php 7.0中删除。

Source

您的其他错误也是同样的问题。使用mysqli_querymysqli_error代替您拥有的内容。

Source