is this the proper way to add multiple text fields at once into mysql?
this works perfect but is this the proper way to do this?
<?
/////////////////add/////////////////////////////////
for ($i=0; $i<count($_POST['newhour_sta开发者_StackOverflow社区rt']); $i++) {
if ($_POST['newhour_start'][$i] !="" && $_POST['newhour_end'][$i] !="" ) {
$inserthour = mysql_query("INSERT INTO hour
(hour_start,hour_end,hour_day) VALUES
('".$_POST['newhour_start'][$i]."','".$_POST['newhour_end'][$i]."','".$_POST['newhour_day'][$i]."')");
}
}
?>
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >
You can insert multiple rows at once:
mysql_query("INSERT INTO hour
(hour_start,hour_end,hour_day) VALUES
(1, 2, 3),
(4, 5, 6)
);
精彩评论