Call to a member function real_escape_string() on a non-object when using MySQLi

前端 未结 1 1154
长发绾君心
长发绾君心 2021-01-15 20:18

I have tried every solution posted on other questions about this topic, but none of them work.

I\'m sorry if this is a basic question, but I\'m new

相关标签:
1条回答
  • 2021-01-15 20:29

    Currently, $connect is out of scope, just add it in the parameter:

    $connect = new mysqli('localhost', 'shop', 'password', 'zen');
    function cleanInput($connect, $string = '') {
        if(!empty($string)) {
            $stripsql = $connect->real_escape_string($string);
            return $stripsql;
        }
    }
    $my_string = 'your string here';
    $escaped_string = cleanInput($connect, $my_string);
    

    Sidenote: Or if you can, you can also use prepared statements.

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