mysqli_real_escape_string() returns empty string

后端 未结 2 397
时光说笑
时光说笑 2020-12-16 06:23

I\'m using mysqli_real_escape_string() on an email address, and it returns an empty string. It does this with any email address.



        
相关标签:
2条回答
  • 2020-12-16 06:45

    I had this problem and found that my character set was set to latin. Solved by putting

    $con->set_charset("utf8");
    

    before the real_escape_string. Would be mysqli_set_charset in procedural style.

    0 讨论(0)
  • 2020-12-16 07:07

    If your connection is empty ($link), it will return an empty string. I tested this and it worked fine. I would recommend that you add error handling to your connection and enable error reporting.

    <?php
    $link = mysqli_connect("localhost", "root", "root", "test");
    
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    $_POST['email'] = "aehmlo@aehmlo.com";
    
    $email = mysqli_real_escape_string($link, $_POST['email']);
    
    var_dump($email);
    
    mysqli_close($link);
    ?>
    

    Result

    string(17) "aehmlo@aehmlo.com"
    0 讨论(0)
提交回复
热议问题