duanlu1922 2013-05-28 03:10
浏览 55
已采纳

通过jquery动态输入并提交到mysql表

I need some advice in the following code.

var count = 1;
$(function(){
    $('#addmore').click(function(){
        count += 1;
        $('ul').append("<li><input type='text' id='hd"+count+"' name='hd"+count+"' value='heading' onClick='this.select();'> <input type='text' id='amount"+count+"' name='amount"+count+"' value='amount' onClick='this.select();'></li>");
//      return false;
    });
});

what exact php code should i use to submit all the input into my test table of mysql.

<button id="addmore">+</button>
<form id="myForm" name="myForm" action="" method="post" onSubmit="return false;">
<ul>
    <li><input type="text" id="hd1" name="hd1" value="heading" onClick="this.select();">
    <input type="text" id="amount1" name="amount1" value="amount" onClick="this.select();"></li>
</ul>
<input type="submit" value="Submit" id="submit" name="submit">
</form>

<?php
if(isset($_POST['submit'])){

echo "h";
};
?>

keeping in mind that i've test table with two fields 'heading' and 'amount'.


if(isset($_POST['submit'])){
    foreach($_POST['hd'] as $hds){
        echo $hds;
        mysqli_query($con,"INSERT INTO test (hdg) VALUES ($hds)");
    };
};

and its not adding data into my table

  • 写回答

1条回答 默认 最新

  • doulai7239 2013-05-28 03:19
    关注

    Use [] for the name attributes instead of the numbers:

    <li><input type="text" id="hd1" name="hd[]" value="heading" onClick="this.select();">
    

    On the server-side you will have an array of values.

    $hd = $_POST['hd']; // Returns an array
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题