在jquery mobile和php mysql中将动态feild数据存储到数据库

时间:2022-02-24 16:40:20

I am creating an order page in Jquery Mobile where user fill data and quantity .

我正在Jquery Mobile中创建一个订单页面,用户填写数据和数量。

Creating Dynamic Fields

创建动态字段

Whenever user fills the data in quantity, say use entered 1, then only one dynamic field will generate. code below

每当用户按数量填充数据时,比如使用输入1,那么将只生成一个动态字段。代码如下

HTML

<label for="textarea2b">Quantity</label>
<input type="number" name="name2" id="quantitypickup" onkeyup="showdimension()" value="" data-clear-btn="true" placeholder="">
  <div id="dimshow" class="row">

JS to show dynamic field

JS显示动态字段

function showdimension() {
    var q = $("#quantitypickup").val();
    var r = $("#dimshow");
    if (q == "0" || q == "" || q == null) {
        r.hide();
        r.html('');
    } else {
        r.show();
        r.html('');
        for (var i = 0; i < q; i++) {
            r.append('  <div class="col-xs-6"><label>Item Name ' + (i + 1) + '</label><input type="text" name="name2" id="itemname" onkeyup="" value="" data-clear-btn="true" placeholder=""></div><div class="col-xs-6"><div class="row"><div class="col-xs-4"><label>Length</label><input type="number" id="length" name="name2"  onkeyup="" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div><div class="col-xs-4"><label>Width</label><input type="number" name="name2" id="width"  onkeyup="" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div><div class="col-xs-4"><label>Height</label><input type="number" id="height" name="name2" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div></div> </div></div>');

        }

    }
}

I want to insert this into database using mysql and php how can I do so. Below is the fiddle https://jsfiddle.net/ankit10594/5suemmyk/ Please help

我想使用mysql和php将其插入数据库,我该怎么办呢。下面是小提琴https://jsfiddle.net/ankit10594/5suemmyk/请帮忙

1 个解决方案

#1


0  

In js: update id & name field

在js中:更新id和名称字段

for (var i = 0; i < q; i++) {
            r.append('  <div class="col-xs-6"><label>Item Name ' + (i + 1) + '</label><input type="text" name="itemname_'+(i+1)+'" id="itemname_'+(i+1)+'" onkeyup="" value="" data-clear-btn="true" placeholder=""></div><div class="col-xs-6"><div class="row"><div class="col-xs-4"><label>Length</label><input type="number" id="length_'+(i+1)+'" name="length_'+(i+1)+'"  onkeyup="" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div><div class="col-xs-4"><label>Width</label><input type="number" name="width_'+(i+1)+'" id="width_'+(i+1)+'"  onkeyup="" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div><div class="col-xs-4"><label>Height</label><input type="number" id="height_'+(i+1)+'" name="height_'+(i+1)+'" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div></div> </div></div>');

        }

Now put all this div & Html inside a <form method='POST' action='<your_page name.php'> tag. & create a submit button. Inside your .php page you can get the value of Quantity from $_POST["name2"].Now useing for() insert the data into database.

现在将所有div&Html放在

标记内。并创建一个提交按钮。在.php页面中,您可以从$ _POST [“name2”]获取Quantity的值。现在使用for()将数据插入数据库。

#1


0  

In js: update id & name field

在js中:更新id和名称字段

for (var i = 0; i < q; i++) {
            r.append('  <div class="col-xs-6"><label>Item Name ' + (i + 1) + '</label><input type="text" name="itemname_'+(i+1)+'" id="itemname_'+(i+1)+'" onkeyup="" value="" data-clear-btn="true" placeholder=""></div><div class="col-xs-6"><div class="row"><div class="col-xs-4"><label>Length</label><input type="number" id="length_'+(i+1)+'" name="length_'+(i+1)+'"  onkeyup="" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div><div class="col-xs-4"><label>Width</label><input type="number" name="width_'+(i+1)+'" id="width_'+(i+1)+'"  onkeyup="" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div><div class="col-xs-4"><label>Height</label><input type="number" id="height_'+(i+1)+'" name="height_'+(i+1)+'" value="" data-clear-btn="true" placeholder=""><label style="text-align:center">inches</label></div></div> </div></div>');

        }

Now put all this div & Html inside a <form method='POST' action='<your_page name.php'> tag. & create a submit button. Inside your .php page you can get the value of Quantity from $_POST["name2"].Now useing for() insert the data into database.

现在将所有div&Html放在

标记内。并创建一个提交按钮。在.php页面中,您可以从$ _POST [“name2”]获取Quantity的值。现在使用for()将数据插入数据库。