我不确定将mysqli_real_escape_string()
放在我当前的MySQL MySQL代码中的位置。
我有URl http://www.example.com/abc-vs-def-vs-ghi/
,但是我知道它可以暴露于http://www.example.com/abc:_?!$123-vs-1312+'
。
我的代码是:
// This I got from my URL - be aware of SQLi!!!
$uri_segments="abc-vs-def-vs-ghi";
// array to get abc def ghi
$compare = explode('-vs-',$uri_segments[0]);
// db connection
$con = mysqli_connect("localhost","user","password","database");
// array for ID's by url segment abc, def, ghi for later
$device_models = array();
// loop array abc def ghi to get the ID from database
foreach ($compare as $model) {
// sql - where to put mysqli_real_escape_string()?
$sql = <<<SQL
SELECT model_id
FROM device_model
WHERE device_model.model_seo_url = '${model}'
SQL;
// get the id for abc, def, ghi
$result = mysqli_query($con, $sql) or die(mysqli_error($con));
while($row = mysqli_fetch_assoc($result)){
$device_model_id = $row['model_id'];
// add id to array
$device_models[] = $device_model_id;
}
}
// close connection
mysqli_close($con);
// id 1,2,3
$var = implode (",", $device_models);
echo $var; // 1,2,3
我应该将ins insie $ sql变量放入'mysqli_real_escape_string(${model})'
吗?
还是'${mysqli_real_escape_string(model)}'
?
我无法正常工作。
也许在foreach()循环内?
谢谢您的帮助!