js动态添加行后,往数据库中插入数据的问题
- HTML code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><!---ecms html部分--><script language="JavaScript"> var cGetRow=-99999;function insertrow(){var newrow = document.all.ACE_HIDDEN_TABLE.rows[0].cloneNode(true); //克隆一行document.all("newTB").appendChild(newrow); //添加刚才克隆的一行}function GetRow(){//获得行索引//两个parentElement分别是TD和TR,rowIndex是TR的属性//this.parentElement.parentElement.rowIndexcGetRow=window.event.srcElement.parentElement.parentElement.rowIndex;DelRow(cGetRow);//点击checkbox时,直接删除行。}function DelRow(iIndex){//删除一行if(iIndex==-99999){alert("系统提示:没有选中行号!");}else{newTB.deleteRow(iIndex);iIndex==-99999;//将rowIndex恢复默认<em style="color:transparent">本@文来源[email protected]搞@^&代*@码网(</em><q>搞代gaodaima码</q>值。}}</script><table border="1"><tr> <td width="40">删除</td> <td width="40">登记</td> <td width="70">用户号码</td> <td width="150">建筑名称</td></tr> <tbody id="ACE_HIDDEN_TABLE"> <tr> <td width="40"></td> <td width="40"></td> <td width="70"></td> <td width="150"></td> </tr></table><table width="1250" border="1"><!---ecms 插入新行的区域 begin --><tbody id="newTB"></tbody><!---ecms 插入新行的区域 end --></table><div align="center" style="margin:10px"><!---ecms --></div>
php部分
- PHP code
$con = mysql_connect("localhost","root","mysql") or die ("连接数据库失败"); //数据库用户名及数据库密码 //数据库名称 mysql_select_db('BERecord'); //数据库名称 mysql_query('set names utf8'); //只有一行插入时的sql语句 $record=$_POST['record']; //登记 //$no=$_POST['no']; //NO、 $usercode=$_POST['usercode']; //用户号码 $buildname=$_POST['buildname']; //建筑名称 for($i=0;$i<3;$i++){ $sql="insert into record(record,usercode,buildname) values('$record[$i]','$usercode[$i]','$buildname[$i]')"; $result=mysql_query($sql,$con); if($result!= 0){ echo "数据插入成功"; echo "
"; echo "正在返回输入页面,跳转中..."; echo "<meta http-equiv='refresh' content='2;url=yanshi.php'>"; } else { echo "插入数据失败"; echo mysql_error(); } }