我需要更改sql语句中的“where-clause”,该语句用于从数据库中获取数据,并通过更改myInput的值并将其传递到服务器端,将其显示在dataTables中。我有这段代码:
<input id=myInput value="london">
<script>
$(document).ready(function(){
$('#example').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "server_processing.php",
"data": function ( d ) {
d.myInput = $('#myInput').val();
}
}
});
} );
</script>
服务器端有这段代码:
<?php
//...HERE I have defined these: $sql_details, $table, $primaryKey, $columns
$where="`office`='$_POST['myInput']'";
require( 'ssp.class.php' );
echo json_encode(SSP::simple($_GET,$sql_details,$table,$primaryKey,$columns,$where));
我哪里错了?我已经尝试过这个基于很多例子并在互联网上发帖但我最终得到的结果相同。
答案 0 :(得分:0)
您的PHP脚本存在一些问题。
$_POST['myInput']
中没有大括号的引用键
语法。$_POST['myInput']
邀请进行SQL注入攻击。SSP::simple
不接受包含WHERE
子句的参数,您需要使用SSP::complex
代替。更正后的代码如下所示:
<?php
//...HERE I have defined these: $sql_details, $table, $primaryKey, $columns
require( 'ssp.class.php' );
$conn = SSP::db($sql_details);
$where="office=".$conn->quote($_POST['myInput']);
echo json_encode(SSP::complex($_GET,$conn,$table,$primaryKey,$columns,$where));