本文介绍了警告:mysqli_real_escape_string()期望正好2个参数,1给出...我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试make php登录,但我得到这个错误:警告:mysqli_real_escape_string()期望正好2个参数,1给出,我做错了什么?

I try make php login but i get this error: Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given, what I do wrong?

register.php

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数据库。

i use 000webhost and this first time when i use mysql databases online.

推荐答案

您正在混合 mysqli mysql 函数

如果你使用的是mysql函数,那么 mysqli_real_escape_string($ your_variable); use

If your are using mysql function then instead mysqli_real_escape_string($your_variable); use

$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_ *函数,那么你必须将你的数据库连接包含到

If your using mysqli_* function then you have to include your connection to database into mysqli_real_escape function :

$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']);

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

Note : Use mysqli_* function since mysql has been deprecated. For information please read mysqli_*

这篇关于警告:mysqli_real_escape_string()期望正好2个参数,1给出...我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:41