Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given… what i do wrong?

前端 未结 11 740
[愿得一人]
[愿得一人] 2020-11-28 12:52

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

相关标签:
11条回答
  • 2020-11-28 13:03

    Replace your query with the following:

    $query = mysql_query("INSERT INTO users VALUES('$username','$pass','$email')", `$Connect`);
    
    0 讨论(0)
  • 2020-11-28 13:07

    you are mixing mysql and mysqli

    use this mysql_real_escape_string like

    $username = mysql_real_escape_string($_POST['username']);
    

    NOTE : mysql_* is deprecated use mysqli_* or PDO

    0 讨论(0)
  • 2020-11-28 13:13

    mysqli_real_escape_string function requires the connection to your database.

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

    P.S.: Do not mix mysql_ functions* and mysqli_ functions*. Please use mysqli_* functions or PDO because mysql_* functions are deprecated and will be removed in the future.

    0 讨论(0)
  • 2020-11-28 13:14

    From the documentation , the function mysqli_real_escape_string() has two parameters.

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

    The first one is a link for a mysqli instance (database connection object), the second one is the string to escape. So your code should be like :

    $username = mysqli_real_escape_string($yourconnectionobject,$_POST['username']);
    
    0 讨论(0)
  • 2020-11-28 13:15

    use mysql_real_escape_string() instead of mysqli_real_escape_string()

    like so:

    $username = mysql_real_escape_string($_POST['username']);
    
    0 讨论(0)
  • 2020-11-28 13:16

    You are mixing mysqli and mysql function.

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

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

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

    0 讨论(0)
提交回复
热议问题