数组插入MYSQL数据库,只能插入最后一行数据,是怎么回事?
C = R.insertCell()
C.innerHTML = "<input type="+"text"+" name="+"name[]"+" style="+"width:50px;font-size: 12px; text-align:center"+">"
}
function deleteRow(obj){
alert(obj.parentElement.parentElement.rowIndex+1);
tbl.deleteRow(obj.parentElement.parentElement.rowIndex);
}
</script>
</head>
<body bgColor="#F7F8F9">
<form name=form1 id="form1" method="post" action= "./tijiao.php">
<table border="1" id="tb" style="font-size: 12px;">
<tr align="center">
<td>姓名</td>
<td>性别</td>
<td>联系电话</td>
<td>收费金额</td>
<td>预定线路</td>
<td>出发日期</td>
<td>出发地</td>
<td>抵达地</td>
<td>起飞时间</td>
<td>抵达时间</td>
<td>航班</td>
<td>返程日期和时间</td>
<td>返程航班</td>
<td>客服</td>
</tr>
<tr align="center">
<td><input type="text" name="name[]" style="width:50px;font-size: 12px; text-align:center" value="<?php echo $applyrs[0][name];?>"></td>
<td><input type="text" name="sex[]" style="width:40px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="shouji[]" style="width:90px;font-size: 12px; text-align:center" value="<?php echo $applyrs[0][shouji];?>"></td>
<td><input type="text" name="price[]" style="width:50px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="line[]" style="width:90px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="cfriqi[]" style="width:100px;font-size: 12px; text-align:center" class="Wdate" onFocus="WdatePicker({isShowClear:false,skin:'whyGreen',lang:'zh-cn'})"></td>
<td><input type="text" name="cfdi[]" style="width:50px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="dddi[]" style="width:50px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="cftime[]" style="width:50px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="ddtime[]" style="width:100px;font-size: 12px; text-align:center" onFocus="WdatePicker({dateFmt:'dd号 HH:mm',lang:'zh-cn'})"></td>
<td><input type="text" name="cfair[]" style="width:60px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="fctime[]" style="width:100px;font-size: 12px; text-align:center" onFocus="WdatePicker({dateFmt:'MM月dd号 HH:mm',lang:'zh-cn'})"></td>
<td><input type="text" name="fcair[]" style="width:50px;font-size: 12px; text-align:center"></td>
<td><input type="text" name="kfname[]" style="width:50px;font-size: 12px; text-align:center"></td>
</tr>
<table name='tb1' id="tbl" border="1" style="font-size: 12px;">
</table>
</table>
<input type="button" value="增加一位游客" onClick="insert_row()">
<br><br>
订单备注:(详细写清楚客人需求,线路游玩时间,大床房等等内容)
<br>
<textarea name="beizhu" cols="140" rows="5"></textarea>
<br><br>
<input name="orderid" type="hidden" value="<?php echo $orderid;?>">
<input name="guanlianddid" type="hidden" value="<?php echo $_REQUEST[appid];?>">
<input name="register" type="submit" value="提交订单" >
<input type="button" value="取消/返加" onClick="history.back()">
</form>
</BODY>
</HTML>
处理页面:
<?mysql 数据库
$db_name="test";
$table_name="chengjiaodingdan";
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());
mysql_query("SET NAMES UTF8");
$cfriqi = date("Y-m-d");
$ddtime = date("dd号 HH:mm");
$fctime = date("MM月dd号 HH:mm");
$chengjiaotime = date("y-m-d",time());
//计算传递过来的文本框的行数
$arr_Length = count($_POST["name"]);
$orderid=$_POST["orderid"];
$name_arr = $_POST["name"];
$sex_arr = $_POST["sex"];
$shouji_arr = $_POST["shouji"];
$price_arr = $_POST["price"];
$line_arr = $_POST["line"];
$cfriqi_arr = $_POST["cfriqi"];
$cfdi_arr = $_POST["cfdi"];
$dddi_arr = $_POST["dddi"];
$cftime_arr = $_POST["cftime"];
$ddtime_arr = $_POST["ddtime"];
$cfair_arr = $_POST["cfair"];
$fctime_arr = $_POST["fctime"];
$fcair_arr = $_POST["fcair"];
$beizhu = $_POST["beizhu"];
$kfname_arr = $_POST["kfname"];
$guanlianddid = $_POST["guanlianddid"];
//循环插入
for($i=0;$i<$arr_Length;$i++){
$sql = "INSERT INTO `chengjiaodingdan` (
`orderid`,
`name`,
`sex`,
`shouji`,
`price`,
`line`,
`lxsline`,
`cfriqi`,
`cfdi`,
`dddi`,
`cftime`,
`ddtime`,
`cfair`,
`fctime`,
`fcair`,
`beizhu`,
`kfname`,
`jiedaifang`,
`lirun`,
`zonglirun`,
`chengjiaotime`,
`zhuangtai`,
`qxyuanying`,
`adminbeizhu`,
`guanlianddid`)";
$sql .="values(
'$orderid',
'$name_arr[$i]',
'$sex_arr[$i]',
'$shouji_arr[$i]',
'$price_arr[$i]',
'$line_arr[$i]',
NULL,
'$cfriqi_arr[$i]',
'$cfdi_arr[$i]',
'$dddi_arr[$i]',
'$cftime_arr[$i]',
'$ddtime_arr[$i]',
'$cfair_arr[$i]',
'$fctime_arr[$i]',
'$fcair_arr[$i]',
'$beizhu',
'$kfname_arr[$i]',
NULL,
NULL,
NULL,
'$chengjiaotime',
'1',
NULL,
NULL,
'$guanlianddid'
)";
}
$query = @mysql_query($sql,$connection) or die(mysql_error());
?>