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

前端 未结 11 741
[愿得一人]
[愿得一人] 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:21

    Use this way instead of your way.

        addslashes(trim($_POST['username']));
    
    0 讨论(0)
  • 2020-11-28 13:22

    pass $connect as your first parameter in mysqli_real_escape_string for this first make connection then do rest.read here http://php.net/manual/en/mysqli.real-escape-string.php

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

    If you use the procedural style, you have to provide both a connection and a string:

    $name = mysqli_real_escape_string($conn, $name);
    

    Only the object oriented version can be done with just a string:

    $name = $link->real_escape_string($name);
    

    The documentation should hopefully make this clear.

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

    The following works perfectly:-

    if(isset($_POST['signup'])){
    $username=mysqli_real_escape_string($connect,$_POST['username']);
    $email=mysqli_real_escape_string($connect,$_POST['email']);
    $pass1=mysqli_real_escape_string($connect,$_POST['pass1']);
    $pass2=mysqli_real_escape_string($connect,$_POST['pass2']);
    

    Now, the $connect is my variable containing my connection to the database. You only left out the connection variable. Include it and it shall work perfectly.

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

    There is slight change in mysql_real_escape_string mysqli_real_escape_string. below syntax

    mysql_real_escape_string syntax will be mysql_real_escape_string($_POST['sample_var'])

    mysqli_real_escape_string syntax will be mysqli_real_escape_string($conn,$_POST['sample_var'])

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