如何使用php
转义并插入mysql数据库<input type="text" name="job_name">
<input type="text" name="job_code">
<input type="text" name="roles[]">
<input type="text" name="roles[]">
<input type="text" name="roles[]">
<input type="text" name="return[]">
<input type="text" name="return[]">
<input type="text" name="return[]">
$job_name = $_POST['job_name'];
$job_code = $_POST['job_code'];
$rool_weight = $_POST['rools'];
$return_weight = $_POST['return'];
如何筛选包括数组和变量在内的所有值。并在非常行和数组上重复插入变量..
答案 0 :(得分:1)
试试这个
// ESCAPE STRING FUNCTION.
function escape_string($string)
{
global $connection;
$escape_string = mysqli_real_escape_string($connection, $string);
return $escape_string;
}
// ESCAPE ARRAY FUNCTION.
function escape_array($array)
{
$arr = is_array($array) ? array_map('escape_string', $array) : $array;
return $arr;
}
$job_name = escape_string($_POST['job_name']);
$job_code = escape_string($_POST['job_code']);
$rool_weight = escape_array($_POST['rools']);
$return_weight = escape_array($_POST['return']);