继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

php 多行数据同时插入

繁星coding
关注TA
已关注
手记 71
粉丝 10
获赞 53


    <?php  
    include "../conn.php";
    echo "<pre>";  
    print_r($_POST["node"]);  
    print_r($_POST["bu"]);  
    print_r($_POST["dmodel"]);  
     
    //计算传递过来的文本框的行数  
    $arr_Length = count($_POST["node"]);  
     
    $node = $_POST["node"];  
    $bu = $_POST["bu"];  
    $dmodel = $_POST["dmodel"];  
     
    /*循环插入语句*/
    for($i=0;$i<$arr_Length;$i++){  
        $sql = "insert into xxmb(node,bu,dmodel)";  
        $sql .= "values('$node[$i]','$bu[$i]','$dmodel[$i]')";  
        
        file_put_contents(a.txt,$sql);
        $query = @mysql_query($sql,$con) or die(mysql_error());  
        //echo $_POST["name"][$i]."<br>";  
    }  
    if($query){
    echo "<script language=javascript> alert('添加成功');</script>";
    }
    ?>
    <!DOCTYPE html PUBLIC   
              "-//W3C//DTD HTML 4.01 Transitional//EN"   
              "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>PHP如何将一组文本框以数组的形式插入数据库</title>
    <script type="text/javascript">
function add(){//欢迎来到站长特效网,我们的网址是www.zzjs.net,很好记,zz站长,js就是js特效,本站收集大量高质量js代码,还有许多广告代码下载。
 var oTr = document.getElementById("addtr").rows[1];
 var newTr = oTr.cloneNode(true);
 document.getElementById("addtr").getElementsByTagName("tbody")[0].appendChild(newTr);
 newTr.cells[0].firstChild.value = newTr.rowIndex;
 newTr.cells[1].firstChild.value = '';
 newTr.cells[2].firstChild.value = '';
 newTr.cells[3].firstChild.value = '';
 newTr.cells[4].firstChild.value = '';
 newTr.cells[5].firstChild.value = '';
 newTr.cells[6].firstChild.value = '';
 newTr.cells[7].firstChild.value = '';
 newTr.cells[8].firstChild.value = '';
 newTr.cells[9].firstChild.value = '';
 document.getElementById("b1").disabled = newTr.rowIndex ==30;
}
</script>
    </head>
    <body>
    <form action="" method="post" >
    <table width="600" border="1">
        <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>职务</th>
        </tr>
        <tr>
            <td>1</td>
            <td><input type="text" name="node[]" value="许亮"></td>
            <td><input type="text" name="bu[]" value="25"></td>
            <td><input type="text" name="dmodel[]" value="SAP开发工程师"></td>
        </tr>
        
       
        <tr>
            <td colspan="4"><input type="submit" value="保存" /></td>
        </tr>
    </table>
    </form>
    </body>
    </html>
    
   

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP