【发布时间】:2016-09-28 14:30:18
【问题描述】:
我正在尝试从多个输入发送多个查询,但名称相同。
这是我需要运行的查询
$sql = "INSERT INTO cv_education VALUES (
'$id', '$school_name', '$school_desc', '$school_start_date', '$school_end_date'
)";
这些是输入
<input type="text" class="form-control" name="school_name[]" id="exampleInputName2"
placeholder="Institution name">
<textarea class="form-control" rows="3" name="school_desc[]"
placeholder="Tell us about what you did there"></textarea>
<input type="number" id="ed_start_date" name="school_start_date[]"
placeholder="Date" value="2015">
<input type="number" id="ed_end_date" name="school_end_date[]"
placeholder="Date" value="2016">
但是用户可以添加更多具有相同名称的输入,我如何从多个具有相同名称的输入中运行多个查询?
我尝试了“foreach”,但它只适用于一个 var。
【问题讨论】:
-
警告:这看起来是terrifyingly insecure。你确定你的用户参数是properly escaped吗?使用带有占位符值的准备好的语句不仅可以解决这个问题,而且意味着您不会因为不正确的转义而花费数小时来追踪一个微小的语法错误。
-
foreach($arr as $key => $val),然后使用$other_array[$key]访问其他并行数组。