0
我想从用户提交的表单中插入一些值到数据库中。PHP插入数据库 - 复杂
$id = mysql_insert_id();//Gets ID of last value inserted into related table
foreach($_POST[ 'equipment' ] as $checkBoxIndex => $checkBoxValue) {
mysql_query("INSERT INTO recipeequipment (recipeid, equipmentid, datetimeentered) VALUES('".$id."', '".$checkBoxValue."', '".$datetime."')");
}
需要加入到这个INSERT语句中的唯一的事情是数量,这是在一个类似的方式复选框举行,但在文本框。像这样:
<?php while($rowequipment = mysql_fetch_assoc($sqlequipment)) {
echo '<input type="checkbox" name="equipment[]" value="'.$rowequipment['equipmentid'].'"/>
<input type="text" name="count[]" id="count[]" size="3" value="" />'
.$rowequipment['description']."<br />";
}?>
我需要帮助的一块是第二个输入列。我需要将与复选框相对应的值插入到插入语句中,但我不确定如何执行此操作。
我会推荐阅读关于sql注入 –
好的SQL注入漏洞。请记住,如果我驾驶这辆数字卡车将他们带到您的网站并在您的服务器上做一些甜甜圈? –
为什么选择复选框?为什么你不能只使用文本字段? –