这是我用来尝试创建多行以插入数据库的形式。
<input name="input[]" type="checkbox" value="0" id="input_0" /> Directional<br /> <br/>
<input name="input[]" type="checkbox" value="1" id="input_1" /> Technical <br />
<br />
<input name="input[]" type="checkbox" value="2" id="input_2" /> Reference <br />
<br />
<input name="input[]" type="checkbox" value="3" id="input_3" /> Research <br />
<br />
<input name="input[]" type="checkbox" value="4" id="input_4" /> Phone <br /></h3>
<input type="submit" name="button" id="button" value="Submit Tally" style="height: 25px; width: 100px">
</Form>
当前使用 implode 从复选框表单将多行插入 mysql 数据库的问题。循环可以解决这个问题吗?选中复选框时,我可以看到数组 (#,#,#,#)
$type = $_POST['input'];
// $sid = $_SERVER['REMOTE_ADDR'];
$user = $_POST['user'];
if(count($type) > 0)
{
$type_string = implode(',', $type);
}
$sql = "INSERT INTO tally (tid, sid, uid, date, time, catid)
VALUE (NULL, 1, '$user', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$type_string')";
mysql_query($sql) or die(mysql_error());
echo "Success";
print_r($type_string);