我需要插入多行數據到表 日期和inspection_id將保持不變 但輸入值重複。 這裏是腳本我有插入多行到一個表使用foreach php
<?php
if (isset($_POST["submit"])) {
$taskdate = date('Y:m:d');
$inspection_id = '1';
$post = $_POST['nfo'];
foreach ($post['point_id'] as $key => $value) {
$point_id.= $value.", ";
}
foreach ($post['point_comment'] as $key => $value) {
$point_comment.= $value.", ";
}
foreach ($post['point_value'] as $key => $value) {
$point_value.= $value.", ";
}
$query = "INSERT INTO `inspections` (`inspection_id`, `point_id`, `value`, `comment`)VALUES('$inspection_id', '$point_id', '$point_value', '$point_comment')";
$result = mysql_query($query);
HTML表單我使用
<form action="pentasks.php" method="post">
<select name="nfo[point_value][]">
<option selected>Chose</option>
<option value="1">Qualify</option>
<option value="2">Disqualify</option>
</select>
<input name = "nfo[point_comment][]" value = "" type="text">
<input type="hidden" name="inspection_id" value="<?= $task_id; ?>"> <!-- value From another query -->
<input type="hidden" name="nfo[point_id][]" value="<?= $spot_id3; ?>">
<input type="submit" name="submit" value="Submit">
</form>
請幫助我如何將數據插入 這個東西在一個表中的問題被定義 在表單中檢索與輸入答案
你是不是做是正確的。你的代碼很容易受到sql注入的影響 – 2014-10-18 13:09:16
爲什麼你用數組命名你的輸入名稱爲'nfo [point_value] []'。那只是一批輸入 – Ghost 2014-10-18 13:10:31