动态文本框数据如何在数据库中插入而不刷新? [英] How dynamic textbox data insert in database without refresh?
本文介绍了动态文本框数据如何在数据库中插入而不刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
我使用以下代码使用动态文本框在数据库中插入数据。它的工作非常出色,但现在我想在没有刷新页面的情况下在数据库中提交数据。
请告知我在哪里以及在哪里更改我的代码。
plz help。在此先感谢:)
OUTPUT.PHP
< pre lang = PHP > <? php
include('connection.php') ;
include('links.php');
if(isset($ _ POST ['save'] ))
{
$ conn = mysql_connect( localhost,root,);
mysql_select_db(esol,$ conn);
$ itemCount = count($ _ POST [ item_name]);
$ itemValues = 0;
$ query = INSERT INTO发票(名称,描述,数量)VALUES ; < span class =code-summarycomment>
$ queryValue = ;
for($ i = 0; $ i< $ itemCount; $ i ++ ) {
if(!empty($ _ POST [item_name] [$ i]) || !empty($ _ POST [item_price] [$ i]) || !empty($ _ POST [quantity] [$ i])) {
$ itemValues ++;
if($ queryValue! = ) {
$ queryValue 。 = , ;
}
$ queryValue 。 = (' 。 $ _ POST [item_name] [$ i] 。 ', ' 。 $ _ POST [item_price] [$ i] 。 ', ' 。 $ _ POST [quantity] [$ i] 。 ') ;
}
< span class =code-summarycomment>}
$ sql = $查询$ queryValue。
if($ itemValues! = 0) {
$ result < span class =code-summarycomment> = mysql_query($ sql);
if(!empty($ result) ) $ message < span class =code-keyword> = 已成功添加。 ;
}
}
? >
< span class =code-keyword>< FORM name = frmProduct 方法 = post action = >
< 输入 类型 = 按钮 名称 = add_item value = 添加更多 onClick = addMore(); / >
< input type = 按钮 na我 = del_item value = 删除 onClick = deleteRow(); / >
< 输入 type = < span class =code-keyword> submit id = save 名称 = 保存 value = 保存 < span class =code-attribute> / >
< / form >
< SCRIPT src = http://code.jquery.com/jquery-2.1.1.js > < / SCRIPT >
< script >
function addMore(){
$()。load(input.php ,function(){
$(#product)。append($(this).html());
});
}
函数deleteRow(){
$('DIV.product-item')。each(function(index,item){
jQuery(':checkbox',this ).each(function(){
if($(this).is(':checked')){
$(item).remove();
}
});
});
}
< / script > < / pre > ;
INPUT.PHP
< DIV class = product-item float-clear style = clear:both; >
< 输入 类型跨度> = 复选框 名称 = item_index [] / >
< 输入 type = text < span class =code-attribute> name = item_name [] / >
< 输入 type = text 名称 = < span class =code-keyword> item_price [] / >
< 输入 类型 = text name = 数量[] / > >
解决方案
_POST ['save ']))
{
< blockquote> conn = mysql_connect( localhost,root,);
mysql_select_db(esol,
conn);
hello friends,
im using following code to insert data in database using dynamic text box. its work excellent but now i want to submit data in database without refresh page.
kindly advise what and where i change my code.
plz help. thanks in advance :)
OUTPUT.PHP
<pre lang="PHP"><?php
include('connection.php');
include('links.php');
if(isset($_POST['save']))
{
$conn = mysql_connect("localhost","root","");
mysql_select_db("esol",$conn);
$itemCount = count($_POST["item_name"]);
$itemValues=0;
$query = "INSERT INTO invoice (name,description,quantity) VALUES ";
$queryValue = "";
for($i=0;$i<$itemCount;$i++) {
if(!empty($_POST["item_name"][$i]) || !empty($_POST["item_price"][$i]) || !empty($_POST["quantity"][$i])) {
$itemValues++;
if($queryValue!="") {
$queryValue .= ",";
}
$queryValue .= "('" . $_POST["item_name"][$i] . "', '" . $_POST["item_price"][$i] . "', '" . $_POST["quantity"][$i] . "')";
}
}
$sql = $query.$queryValue;
if($itemValues!=0) {
$result = mysql_query($sql);
if(!empty($result)) $message = "Added Successfully.";
}
}
?>
<FORM name="frmProduct" method="post" action="">
<input type="button" name="add_item" value="Add More" onClick="addMore();" />
<input type="button" name="del_item" value="Delete" onClick="deleteRow();" />
<input type="submit" id="save" name="save" value="Save" />
</form>
<SCRIPT src="http://code.jquery.com/jquery-2.1.1.js"></SCRIPT>
<script>
function addMore() {
$("").load("input.php", function() {
$("#product").append($(this).html());
});
}
function deleteRow() {
$('DIV.product-item').each(function(index, item){
jQuery(':checkbox', this).each(function () {
if ($(this).is(':checked')) {
$(item).remove();
}
});
});
}
</script></pre>
INPUT.PHP
<DIV class="product-item float-clear" style="clear:both;">
<input type="checkbox" name="item_index[]" />
<input type="text" name="item_name[]" />
<input type="text" name="item_price[]" />
<input type="text" name="quantity[]" />>
解决方案
_POST['save'])) {
conn = mysql_connect("localhost","root",""); mysql_select_db("esol",
conn);
这篇关于动态文本框数据如何在数据库中插入而不刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文