dongyi1939 2014-06-21 04:23
浏览 71

使用javascript动态插入新行,但如何在php / mysql中保存这些多行

I have create multiple row by using javascript. Now how to save these row in mysql. I already using some type of code, its not working. here my code is [http://jsfiddle.net/bb2pJ/] and php code for adding these value.

`

include "config.php";

if(isset($_POST['submit']))
{

 foreach ($_POST['code1'] as $key => $value) 
    {
        $code1 = $_POST["code1"][$key];
        $product1 = $_POST["product_name1"][$key];
        $qty = $_POST["quantity1"][$key];
        $rate = $_POST["amount_name1"][$key];
        $total = $_POST["total_name1"][$key];


        $sql = mysql_query("insert into      testing(code,product,qty,rate,total)values('$code1','$product1','$qty1','$rate1','$total1')")or die(mysql_error());        
    }

}   
?>`
  • 写回答

1条回答 默认 最新

  • dsasd12314 2014-06-21 10:08
    关注

    From you Js fiddle code, you are trying to post array of values for each field (ie code, proddname, ...).

    How are submitting these values? If not passing through ajax post, then you need to declare fields names like code[], product_name[] ... as array for all fields so they will be submitted as array.

    Rest code you have writtten above should work by using proper field name like code for code[] ... .

    Please put proper spacing between your keywords and values/fieldname in your insert into.. statement.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题