【问题标题】:MySQLi Error: addcslashes() expects exactly 2 parameters, 1 givenMySQLi 错误:addcslashes() 需要 2 个参数,1 个给定
【发布时间】:2017-07-04 17:16:32
【问题描述】:

我有这段代码会产生以下错误:

警告:addcslashes() 需要 2 个参数,第 10 行给出 1 个

我的代码是:

$searchtype = isset($_POST['searchtype']) ? $_POST['searchtype'] : null;
$searchterm = isset($_POST['searchterm']) ? $_POST['searchtype'] : null;
$searchterm = trim($searchterm);
if (!$searchtype || !$searchterm) {
    echo 'You are not entered search detail. Please go back and try again';
}
if (!get_magic_quotes_gpc()) {
    $searchtype = addcslashes($searchtype);//line 10 with error
    $searchterm = addcslashes($searchterm);//line with error
}
@ $db = new msqli('localhost','root','','sales');
if (mysqli_connect_errno()) {
    echo 'Error: Could not connect to database. Please try again leter.';
    exit;
}

【问题讨论】:

  • 好的,问题出在哪里?
  • 似乎最简单的解决方法就是使用 addslashes 而不是 addCslashes.. 但是 C 版本确实需要 2 个参数
  • 我建议您阅读prepared statements 并使用它。不需要escapeaddslashes

标签: php laravel


【解决方案1】:

就像你的错误所说,你必须使用两个参数来addcslashes 像这样:

addcslashes($searchtype,"W");

见: https://www.w3schools.com/php/func_string_addcslashes.asp

【讨论】:

    【解决方案2】:

    您正在使用 addcslashes 方法,该方法需要 http://php.net/manual/en/function.addcslashes.php 中所述的 2 个参数

    您可能正在寻找addslashes($searchtype)

    【讨论】:

      【解决方案3】:

      我刚遇到同样的情况,需要在两个数组中使用相同的键,所以我最终这样做了,它对我来说效果很好:

      let jsarray = {
                    <?php
                      foreach ($phparray as $key => $value) {
                        echo $key.':'.'"'.addslashes($value).'",';
                      }
                    ?>
                  };
      

      【讨论】:

        【解决方案4】:

        您需要第二个参数,它是您要转义的字符列表。例如:

        echo addcslashes("Hello world", array("l")); // => He\l\lo wor\ld
        

        Here is more information about this very topic.

        【讨论】:

          【解决方案5】:

          使用addslashes 而不是addcslashes,您的问题就解决了。

          【讨论】:

            猜你喜欢
            • 2010-11-11
            • 1970-01-01
            • 1970-01-01
            • 2016-03-24
            • 2012-10-08
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多