如何提交js插入行的数据 <input type = 'text' style='width:100%' name = 'duty[]' /> 这样命名。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 post提交?提交不了?你是用js提交?贴出input 标签属性看看,看你是否正确获取到input属性的值。 代码比较多,请各位看官慢看。一:动态增加行的js代码var index; index = 1; function insertRow(){ var s1 = "<input type = 'text' style='width:100%' name = 'duty' />"; var s2 = "<input type = 'text' style='width:100%' name = 'place' />"; var s3 = "<input type = 'text' style='width:100%' name = 'ephone' />"; var s4 = "<input type = 'text' style='width:100%' name = 'sec' />"; var s5 = "<input type = 'text' style='width:100%' name = 'sphone' />"; var s6 = "<input type = 'text' style='width:100%' name = 'olset' />"; var s7 = "<input type = 'text' style='width:100%' name = 'olex' />"; var s8 = "<input type = 'text' style='width:100%' name = 'vpnex' />"; var s9 = "<input type = 'text' style='width:100%' name = 'tokenex' />"; var s10 = "<a href = javascript:delRow('"+index+ "')><img src='pic/49882.png' border='0' width='10' height='10' /></a>"; var table = document.getElementById('table1'); row = table.insertRow(index); /*insertRow() 方法用于在表格中的指定位置插入一个新行。 语法tableObject.insertRow(index)返回值 返回一个 TableRow,表示新插入的行。 说明 该方法创建一个新的 TableRow 对象,表示一个新的 <tr> 标记,并把它插入表中的指定位置。 新行将被插入 index 所在行之前。若 index 等于表中的行数,则新行将被附加到表的末尾。 如果表是空的,则新行将被插入到一个新的 <tbody> 段,该段自身会被插入表中。 num = document.getElementById("tbl").rows.length; R = tbl.insertRow(num-2); //倒数第2行插入 抛出 若参数 index 小于 0 或大于等于表中的行数,该方法将抛出代码为 INDEX_SIZE_ERR 的 DOMException 异常。*/row.id = "tr" + index; c1 = row.insertCell(-1);//插入列td,一个一个插入,代码用innerHTML写入c1.innerHTML = s1; c2 = row.insertCell(-1); c2.innerHTML = s2; c3 = row.insertCell(-1); c3.innerHTML = s3; c4 = row.insertCell(-1); c4.innerHTML = s4; c5 = row.insertCell(-1); c5.innerHTML = s5; c6 = row.insertCell(-1); c6.innerHTML = s6; c7 = row.insertCell(-1); c7.innerHTML = s7; c8 = row.insertCell(-1); c8.innerHTML = s8; c9 = row.insertCell(-1); c9.innerHTML = s9; c10 = row.insertCell(-1); c10.innerHTML = s10; } function delRow(index){ var table = document.getElementById('table1'); table.deleteRow(document.getElementById("tr" + index).rowIndex); this.index = this.index - 1;二.FORM内容<form action="proinsert.php" method="post"> <div id="header"> <div id="hl"></div> <div id="hm">成都VIP档案-<?php echo "$enname"?> </div> <div id="hr"> <input type="button" onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" onclick="javascript:history.back(-1);" value="返回上一页"><input type="button" onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" onclick="location.href=('vip.php')" value="返回主页"> </div> </div> <div id="line1"></div> <div id="header"> <div id="header1"> <div id="inheader1">帐号信息</div> <input type="button" id="b1" value="添加" onclick="insertRow()" /> </div> <div id="header2"> <input name="mysubmit" type="submit" value="提交" onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:30px; font-size:14px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" /> </div> </div> <div id="m"> <table id="table1" align="center" width="1200px" border="0px" > <th style="width:150px; color:#FF6666;" >职务</th> <th style="color:#FF6666;">办公地点</th> <th style="width:50px; color:#FF6666;">分机号</th> <th style="width:50px; color:#FF6666;">秘书</th> <th style="width:50px; color:#FF6666;">分机号</th> <th style="color:#FF6666;">outlook修改时间</th> <th style="color:#FF6666;">outlook有效期</th> <th style="color:#FF6666;">VPN有效期</th> <th style="color:#FF6666;">Token有效期</th> <th style="width:50px; color:#FF6666;">删除</th> <script language="php"> $sql="select * from profile where enname='$enname'"; $rst = mysql_query($sql); while($row=mysql_fetch_array($rst)){ $nowtime=strtotime('+7 day'); $olex=strtotime($row['olex']) ; $vpnex=strtotime($row['vpnex']) ; $tokenex=strtotime($row['tokenex']) ; $vpnex_style = $nowtime>=$vpnex ? ' style="color:red"' : ''; $olex_style = $nowtime>=$olex ? ' style="color:red"' : ''; $token_style = $nowtime>=$tokenex ? ' style="color:red"' : ''; echo " <input type='hidden' style='width:100%' name='id' value='$row[id]'/> <input type='hidden' style='width:100%' name='enname' value='$row[enname]'/> <input type='hidden' style='width:100%' name='chname' value='$row[chname]'/> <input type='hidden' style='width:100%' name='person' value='$array[1]'/> <tr> <td><input type='text' style='width:100%' name='duty' value='$row[duty]'/></td> <td><input type='text' style='width:100%' name='place' value='$row[place]'/></td> <td><input type='text' style='width:100%' name='ephone' value='$row[ephone]'/></td> <td><input type='text' style='width:100%' name='sec' value='$row[sec]'/></td> <td><input type='text' style='width:100%' name='sphone' value='$row[sphone]'/></td> <td><input type='text' style='width:100%' name='olset' value='$row[olset]'/></td> <td><input type='text' style='width:100%' name='olex' value='$row[olex]'/></td> <td><input type='text' style='width:100%' name='vpnex' value='$row[vpnex]'/></td> <td><input type='text' style='width:100%' name='tokenex' value='$row[tokenex]'/></td> <td><a href='prodelete.php?ID=$row[id]' /a><img src='pic/49882.png' border='0' width='10' height='10' /></a></td> </tr>"; } </script> </table> <table align="center" width="1200px" border="0px" > </table> </div> </form>三.提交页面proinsert.php关键代码if($_POST["mysubmit"]=='提交' ) { $exec="replace INTO profile (id,enname,chname, duty, place,ephone,sec, sphone, olset, olex,vpnex,tokenex,person,dtime) VALUES ('$_POST[id]','$_POST[enname]','$_POST[chname]','$_POST[duty]','$_POST[place]','$_POST[ephone]','$_POST[sec]','$_POST[sphone]','$_POST[olset]','$_POST[olex]','$_POST[vpnex]','$_POST[tokenex]','$_POST[person]',now())"; if (!mysql_query($exec,$con)) { die('数据库错误提示: ' . mysql_error()); } header("Location:detail.php?enname=$enname"); } mysql_close($con); innerHTML方式插入在某些浏览器中貌似不认,建议改成appendChild方式插入,或者直接用jquery的append( )方法插入 “非常PHP”QQ群开通 php和cookie的问题!在先等 请问这个简单的查询还有没有优化的余地 两个数相乘$temp=215852.00*0.068; echo $temp;也能出错,这是为什么呢?谢谢 象DZ这样的错误提示怎么实现? phpmyadmin安装时的乱码问题 PHP的十个高级技巧之十——PHP和XML 在redhat9.0下安装php几个问题? 这统计两张表总数的sql语句为何不准确 怎么数据库联不上? 求将一段递归代码改为非递归形式 41778.00000000 是一种怎样的时间记录格式
你是用js提交?贴出input 标签属性看看,看你是否正确获取到input属性的值。
代码比较多,请各位看官慢看。一:动态增加行的js代码
var index;
index = 1;
function insertRow(){
var s1 = "<input type = 'text' style='width:100%' name = 'duty' />";
var s2 = "<input type = 'text' style='width:100%' name = 'place' />";
var s3 = "<input type = 'text' style='width:100%' name = 'ephone' />";
var s4 = "<input type = 'text' style='width:100%' name = 'sec' />";
var s5 = "<input type = 'text' style='width:100%' name = 'sphone' />";
var s6 = "<input type = 'text' style='width:100%' name = 'olset' />";
var s7 = "<input type = 'text' style='width:100%' name = 'olex' />";
var s8 = "<input type = 'text' style='width:100%' name = 'vpnex' />";
var s9 = "<input type = 'text' style='width:100%' name = 'tokenex' />";
var s10 = "<a href = javascript:delRow('"+index+ "')><img src='pic/49882.png' border='0' width='10' height='10' /></a>"; var table = document.getElementById('table1');
row = table.insertRow(index);
/*insertRow() 方法用于在表格中的指定位置插入一个新行。
语法tableObject.insertRow(index)
返回值 返回一个 TableRow,表示新插入的行。
说明
该方法创建一个新的 TableRow 对象,表示一个新的 <tr>
标记,并把它插入表中的指定位置。
新行将被插入 index 所在行之前。若 index
等于表中的行数,则新行将被附加到表的末尾。
如果表是空的,则新行将被插入到一个新的 <tbody> 段,该段自身会被插入表中。
num = document.getElementById("tbl").rows.length;
R = tbl.insertRow(num-2); //倒数第2行插入
抛出
若参数 index 小于 0 或大于等于表中的行数,该方法将抛出代码为 INDEX_SIZE_ERR 的 DOMException 异常。*/
row.id = "tr" + index;
c1 = row.insertCell(-1);//插入列td,一个一个插入,代码用innerHTML写入
c1.innerHTML = s1; c2 = row.insertCell(-1);
c2.innerHTML = s2; c3 = row.insertCell(-1);
c3.innerHTML = s3;
c4 = row.insertCell(-1);
c4.innerHTML = s4; c5 = row.insertCell(-1);
c5.innerHTML = s5; c6 = row.insertCell(-1);
c6.innerHTML = s6; c7 = row.insertCell(-1);
c7.innerHTML = s7; c8 = row.insertCell(-1);
c8.innerHTML = s8; c9 = row.insertCell(-1);
c9.innerHTML = s9; c10 = row.insertCell(-1);
c10.innerHTML = s10; }
function delRow(index){ var table = document.getElementById('table1');
table.deleteRow(document.getElementById("tr" + index).rowIndex);
this.index = this.index - 1;
二.FORM内容
<form action="proinsert.php" method="post">
<div id="header">
<div id="hl"></div>
<div id="hm">
成都VIP档案-<?php echo "$enname"?>
</div>
<div id="hr">
<input type="button" onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" onclick="javascript:history.back(-1);" value="返回上一页"><input type="button" onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" onclick="location.href=('vip.php')" value="返回主页">
</div> </div>
<div id="line1"></div>
<div id="header">
<div id="header1">
<div id="inheader1">
帐号信息
</div>
<input type="button" id="b1" value="添加" onclick="insertRow()" />
</div>
<div id="header2">
<input name="mysubmit" type="submit" value="提交" onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:30px; font-size:14px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;" />
</div>
</div>
<div id="m">
<table id="table1" align="center" width="1200px" border="0px" >
<th style="width:150px; color:#FF6666;" >职务</th>
<th style="color:#FF6666;">办公地点</th>
<th style="width:50px; color:#FF6666;">分机号</th>
<th style="width:50px; color:#FF6666;">秘书</th>
<th style="width:50px; color:#FF6666;">分机号</th>
<th style="color:#FF6666;">outlook修改时间</th>
<th style="color:#FF6666;">outlook有效期</th>
<th style="color:#FF6666;">VPN有效期</th>
<th style="color:#FF6666;">Token有效期</th>
<th style="width:50px; color:#FF6666;">删除</th>
<script language="php"> $sql="select * from profile where enname='$enname'";
$rst = mysql_query($sql); while($row=mysql_fetch_array($rst)){
$nowtime=strtotime('+7 day');
$olex=strtotime($row['olex']) ;
$vpnex=strtotime($row['vpnex']) ;
$tokenex=strtotime($row['tokenex']) ;
$vpnex_style = $nowtime>=$vpnex ? ' style="color:red"' : '';
$olex_style = $nowtime>=$olex ? ' style="color:red"' : '';
$token_style = $nowtime>=$tokenex ? ' style="color:red"' : '';
echo "
<input type='hidden' style='width:100%' name='id' value='$row[id]'/>
<input type='hidden' style='width:100%' name='enname' value='$row[enname]'/>
<input type='hidden' style='width:100%' name='chname' value='$row[chname]'/>
<input type='hidden' style='width:100%' name='person' value='$array[1]'/> <tr>
<td><input type='text' style='width:100%' name='duty' value='$row[duty]'/></td>
<td><input type='text' style='width:100%' name='place' value='$row[place]'/></td>
<td><input type='text' style='width:100%' name='ephone' value='$row[ephone]'/></td>
<td><input type='text' style='width:100%' name='sec' value='$row[sec]'/></td>
<td><input type='text' style='width:100%' name='sphone' value='$row[sphone]'/></td>
<td><input type='text' style='width:100%' name='olset' value='$row[olset]'/></td>
<td><input type='text' style='width:100%' name='olex' value='$row[olex]'/></td>
<td><input type='text' style='width:100%' name='vpnex' value='$row[vpnex]'/></td>
<td><input type='text' style='width:100%' name='tokenex' value='$row[tokenex]'/></td> <td><a href='prodelete.php?ID=$row[id]' /a><img src='pic/49882.png' border='0' width='10' height='10' /></a></td>
</tr>";
}
</script>
</table> <table align="center" width="1200px" border="0px" >
</table> </div>
</form>三.提交页面proinsert.php关键代码
if($_POST["mysubmit"]=='提交' ) {
$exec="replace INTO profile (id,enname,chname, duty, place,ephone,sec, sphone, olset, olex,vpnex,tokenex,person,dtime)
VALUES
('$_POST[id]','$_POST[enname]','$_POST[chname]','$_POST[duty]','$_POST[place]','$_POST[ephone]','$_POST[sec]','$_POST[sphone]','$_POST[olset]','$_POST[olex]','$_POST[vpnex]','$_POST[tokenex]','$_POST[person]',now())";
if (!mysql_query($exec,$con))
{
die('数据库错误提示: ' . mysql_error());
} header("Location:detail.php?enname=$enname");
}
mysql_close($con);