警告:mysqli

我尝试使php登录,但我得到这个错误: Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given,我做错了什么?

register.php

<!doctype html>
<html lang"fi">
<head>
<link rel="icon" type='image/png' href='images/logo.png'>
<title>
asd
</title>
<link href="css/styles.css" type="text/css" rel="stylesheet">
</head>
<body>
<!--reg alkaa-->
<form action="register.php" method="post">
<p><input type="text" name="username" placeholder="Username">
<p><input type="email" name="email" placeholder="Email">
<p><input type="password" name="pass" placeholder="Password">
<p><input type="password" name="pass1" placeholder="Password">
<p><input type="submit" name="submit" value="Register">
</form>
<?php

if(isset($_POST['submit']))
{
$username = mysqli_real_escape_string($_POST['username']);
$pass = mysqli_real_escape_string($_POST['pass']);
$pass1 = mysqli_real_escape_string($_POST['pass1']);
$email = mysqli_real_escape_string($_POST['email']);
if($username && $pass && $pass1 && $email)
{
if($pass==$pass1)
{
    $connect = mysql_connect("mysql13.000webhost.com","a2955851_SW","ASPIREX1930");
    mysql_select_db("a2955851_SW");
    $query = mysql_query("INSERT INTO users VALUES('$username','$pass','$email');");
    echo "You have been registered.";
}
else
{
    echo "Password must match.";
}
}
else
{
echo "All fields are required.";
}
}
 ?>
<!--reg end-->
<Center>
<a href="index.php">
<h1>
asd
</h1>
</center>
<div id="main">
<h3>
 <div class="menu"> <a href="index.php">Etusivu</a> &bullet; 
 <a                                       </div>
</h3>
</div>
<div class="jonne"> 
</div>
<script src="javascript/jquery.js"></script>
</body>
</html>

我使用000webhost,这是我第一次在线使用mysql数据库。


你在混合mysqlimysql函数。

如果你正在使用mysql函数,那么改为mysqli_real_escape_string($your_variable); 使用

$username = mysql_real_escape_string($_POST['username']);
$pass = mysql_real_escape_string($_POST['pass']);
$pass1 = mysql_real_escape_string($_POST['pass1']);
$email = mysql_real_escape_string($_POST['email']);

如果你使用mysqli_ *函数,那么你必须将你的连接数据库包含到mysqli_real_escape函数中

$username = mysqli_real_escape_string($your_connection, $_POST['username']);
$pass = mysqli_real_escape_string($your_connection, $_POST['pass']);
$pass1 = mysqli_real_escape_string($your_connection, $_POST['pass1']);
$email = mysqli_real_escape_string($your_connection, $_POST['email']);

注意:由于mysql已被弃用,请使用mysqli_ *函数。 有关信息,请阅读mysqli_ *


从文档中,函数mysqli_real_escape_string()有两个参数。

string mysqli_real_escape_string ( mysqli $link , string $escapestr ).

第一个是mysqli实例(数据库连接对象)的链接,第二个是要转义的字符串。 所以你的代码应该是这样的:

$username = mysqli_real_escape_string($yourconnectionobject,$_POST['username']);

mysqli_real_escape_string函数需要连接到你的数据库。

$username = mysqli_real_escape_string($your_connection, $_POST['username']);

PS:不要混用mysql_函数*mysqli_函数* 。 请使用mysqli_* functions or PDO因为mysql_ *函数已被弃用,将来会被删除。

链接地址: http://www.djcxy.com/p/93641.html

上一篇: Warning: mysqli

下一篇: Why does my grunt