Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 需要帮助防止sql注入吗_Php_Mysql - Fatal编程技术网

Php 需要帮助防止sql注入吗

Php 需要帮助防止sql注入吗,php,mysql,Php,Mysql,嗨,我有以下声明 function count_rows($table_name, $condition = null, $debug = false) { $query_result = $this->query("SELECT count(*) AS count_rows FROM " . $this->db_prefix . $table_name . " " . $condition, $debug); $count_rows = $this->sql_

嗨,我有以下声明

function count_rows($table_name, $condition = null, $debug = false)
{
    $query_result = $this->query("SELECT count(*) AS count_rows FROM " . $this->db_prefix . $table_name . " " . $condition, $debug);
    $count_rows = $this->sql_result($query_result, 0, 'count_rows');

    return $count_rows;
}
我一直在使用firefox的SQLInjectMe插件,它给了我一个错误

运行脚本时发生Mysql错误:

The query you are trying to run is invalid
Mysql Error Output: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 2
SQL Query: SELECT count(*) AS count_rows FROM database_auctions a WHERE a.active=1 AND a.approved=1 AND a.deleted=0 AND a.list_in!='store' AND a.catfeat='1' AND a.closed=0 AND (a.category_id IN ())

如何针对sql注入清理此查询???

您可以在查询的这一部分附近看到:

和(a.category\u id IN())

实际上,您并没有给它一个子查询/值列表。您需要这样做以确定结果是否包含指定的类别id

为了防止sql注入,我建议使用PHP中的mysqli扩展。我认为他们支持事先准备好的声明。通过使用prepared语句,您将放弃使用字符串连接,服务器将“准备”sql语句,因此查询只发送到服务器一次,然后在实际执行sql查询时只发送参数


当您传递
$contidion
时,您似乎忘记了此处的某个内容
a.category\u id IN()
在父项之间应该是值。
为了避免SQL注入检查

清理无效查询?我不明白。嗨,伙计们,让我解释一下,我使用了插件sql inject me,在发布字段“或用户名不为NULL或用户名=”后出现了错误,它通常不是无效查询,工作正常