在ajax中验证来自外部php的动态添加的表行值(Validating dynamically added table row values from external php in ajax)
我正在使用一个由动态值组成的表单,例如在按钮单击时添加表行,我使用jQuery执行此操作,但现在我甚至想在将数据插入数据库之前验证我的数据。
我不得不使用外部PHP文件进行此验证我使用AJAX进行此验证,但验证工作正常,但数据仍然插入到我的数据库中。 我尽了最大努力,但仍然不适合我。
这是我的代码:
function update_db(){ var udata = {}; var adata = {}; del_query = new Array(); var confirm = 0; var a = "1"; if ($("#maintable tbody tr").length>0){ var vendorid = $("#vendorinfo").val(); // prepare data to be updated $('[id^="dbtr_"]').each(function(index, table){ var rid = $('th:eq(0)', this).find('input:eq(0)').val(); var basecatid = $('td:eq(0)', this).find('select:eq(0)').val(); var subvendorid = $('td:eq(0)', this).find('select:eq(0)').val(); var prodid = $('td:eq(1)', this).find('input:eq(1)').val(); var productname = $('td:eq(1)', this).find('input:eq(0)').val(); var quantity = $('td:eq(2)', this).find('input:eq(0)').val(); var muc = $('td:eq(3)', this).find('#muid').val(); var amt = $('td:eq(4)', this).find('input:eq(0)').val(); var reason = $('td:eq(5)', this).find('textarea:eq(0)').val(); var vat_percentage = $('td:eq(5)', this).find('input:eq(0)').val(); var total_amount_before_vat = $('td:eq(5)', this).find('input:eq(1)').val(); var vat_charged_in_bill = $('td:eq(5)', this).find('input:eq(2)').val(); var invoice = $('td:eq(6)', this).find('input:eq(0)').val(); if(invoice =='' && prodid !=''){ alert("Invoice Number Cannot Be Empty"); $("#savetodb").prop("disabled", true); a = "0"; return false; } if( quantity !='' && invoice !=''){ var vouchdt = $("#dateinfo").val(); $.ajax({ type: "POST", url: "../model/check_procurement_resold_with_invoice_number.php", data: { para : "upd", invno : invoice, product : prodid, date : vouchdt, quantity : quantity}, success: function(result){ if(result == "") { alert(productname+" does not exist for invoice number "+invoice); a = "0"; return false } if(result == "2") { alert("Quantity "+ quantity +" for "+productname+" can't be greater than the quantity procured for invoice number "+invoice+" 1"); a = "0"; return false; } } }); } if (prodid != 'NA' && muc != '' && amt > 0 && rid != '') { if (quantity>0){ udata[rid] = {}; udata[rid]['sub_vendor_id'] = subvendorid; udata[rid]['procurement_vendor_id'] = vendorid; udata[rid]['product_id'] = prodid; udata[rid]['quantity'] = quantity; udata[rid]['measurement_unit'] = muc; udata[rid]['amount_received'] = amt; udata[rid]['reason'] = reason; udata[rid]['vat_percentage'] = vat_percentage; udata[rid]['total_amount_before_vat'] = total_amount_before_vat; udata[rid]['vat_charged_in_bill'] = vat_charged_in_bill; udata[rid]['invoice_number'] = invoice; } else{ del_query.push(rid); } } }); if(a =='1'){ $.ajax({ type: "POST", url: "../model/bulk_procurement_resold_at_lowprice.php", data: {action:'updatedb',ud:udata,ad:adata,dd:del_query,username:'<?=$gotuser?>'}, success: function(result){ results = JSON.parse(result); alert('Number of records Updated : '+results['utotal_s']+"\nNumber Of records Inserted : "+results['acnt']+"\nNumber of records Deleted : "+results['dcnt']); // window.location.href="bulk_procurement_resold_at_lowprice.php?vendorinfo="+vendorid+"&dateinfo="+$("#dateinfo").val()+"&catinfo="+$("#catinfo").val(); } }); }
这是我的php文件
$proid = $_POST['product']; $code = mysql_real_escape_string($_POST["invno"]); $vouchdt = mysql_real_escape_string($_POST["date"]); $qty = mysql_real_escape_string($_POST["quantity"]); $chkqty = mysql_query("SELECT a.quantity_procured, b.invoice_number FROM `gc_procurement_daily_detail` a, `gc_procurement_daily_summary` b WHERE a.product_id='".$proid."' AND b.`date_of_invoice`='".$vouchdt."' AND b.invoice_number='".$code."' AND a.`procurement_daily_summary_id`= b.procurement_daily_summary_id")or die(mysql_error()); if(mysql_num_rows($chkqty) > 0){ $gqty =0; while($row = mysql_fetch_object($chkqty)){ $mqty = $row->quantity_procured; $gqty = $gqty + $mqty; } if($qty <= $gqty){ echo 1; }else{ echo 2; } }else{ echo ''; }
I am working with a form which consist of dynamic values like adding table rows on button click and I am doing this with jQuery, but now I even want to validate my data before inserting it into my database.
I had to do this validation with external PHP file I am doing this with AJAX, but the validation is working well but still the data is being inserted into my database. I have tried my best but still its not working for me.
Here is my code:
function update_db(){ var udata = {}; var adata = {}; del_query = new Array(); var confirm = 0; var a = "1"; if ($("#maintable tbody tr").length>0){ var vendorid = $("#vendorinfo").val(); // prepare data to be updated $('[id^="dbtr_"]').each(function(index, table){ var rid = $('th:eq(0)', this).find('input:eq(0)').val(); var basecatid = $('td:eq(0)', this).find('select:eq(0)').val(); var subvendorid = $('td:eq(0)', this).find('select:eq(0)').val(); var prodid = $('td:eq(1)', this).find('input:eq(1)').val(); var productname = $('td:eq(1)', this).find('input:eq(0)').val(); var quantity = $('td:eq(2)', this).find('input:eq(0)').val(); var muc = $('td:eq(3)', this).find('#muid').val(); var amt = $('td:eq(4)', this).find('input:eq(0)').val(); var reason = $('td:eq(5)', this).find('textarea:eq(0)').val(); var vat_percentage = $('td:eq(5)', this).find('input:eq(0)').val(); var total_amount_before_vat = $('td:eq(5)', this).find('input:eq(1)').val(); var vat_charged_in_bill = $('td:eq(5)', this).find('input:eq(2)').val(); var invoice = $('td:eq(6)', this).find('input:eq(0)').val(); if(invoice =='' && prodid !=''){ alert("Invoice Number Cannot Be Empty"); $("#savetodb").prop("disabled", true); a = "0"; return false; } if( quantity !='' && invoice !=''){ var vouchdt = $("#dateinfo").val(); $.ajax({ type: "POST", url: "../model/check_procurement_resold_with_invoice_number.php", data: { para : "upd", invno : invoice, product : prodid, date : vouchdt, quantity : quantity}, success: function(result){ if(result == "") { alert(productname+" does not exist for invoice number "+invoice); a = "0"; return false } if(result == "2") { alert("Quantity "+ quantity +" for "+productname+" can't be greater than the quantity procured for invoice number "+invoice+" 1"); a = "0"; return false; } } }); } if (prodid != 'NA' && muc != '' && amt > 0 && rid != '') { if (quantity>0){ udata[rid] = {}; udata[rid]['sub_vendor_id'] = subvendorid; udata[rid]['procurement_vendor_id'] = vendorid; udata[rid]['product_id'] = prodid; udata[rid]['quantity'] = quantity; udata[rid]['measurement_unit'] = muc; udata[rid]['amount_received'] = amt; udata[rid]['reason'] = reason; udata[rid]['vat_percentage'] = vat_percentage; udata[rid]['total_amount_before_vat'] = total_amount_before_vat; udata[rid]['vat_charged_in_bill'] = vat_charged_in_bill; udata[rid]['invoice_number'] = invoice; } else{ del_query.push(rid); } } }); if(a =='1'){ $.ajax({ type: "POST", url: "../model/bulk_procurement_resold_at_lowprice.php", data: {action:'updatedb',ud:udata,ad:adata,dd:del_query,username:'<?=$gotuser?>'}, success: function(result){ results = JSON.parse(result); alert('Number of records Updated : '+results['utotal_s']+"\nNumber Of records Inserted : "+results['acnt']+"\nNumber of records Deleted : "+results['dcnt']); // window.location.href="bulk_procurement_resold_at_lowprice.php?vendorinfo="+vendorid+"&dateinfo="+$("#dateinfo").val()+"&catinfo="+$("#catinfo").val(); } }); }
here is my php file
$proid = $_POST['product']; $code = mysql_real_escape_string($_POST["invno"]); $vouchdt = mysql_real_escape_string($_POST["date"]); $qty = mysql_real_escape_string($_POST["quantity"]); $chkqty = mysql_query("SELECT a.quantity_procured, b.invoice_number FROM `gc_procurement_daily_detail` a, `gc_procurement_daily_summary` b WHERE a.product_id='".$proid."' AND b.`date_of_invoice`='".$vouchdt."' AND b.invoice_number='".$code."' AND a.`procurement_daily_summary_id`= b.procurement_daily_summary_id")or die(mysql_error()); if(mysql_num_rows($chkqty) > 0){ $gqty =0; while($row = mysql_fetch_object($chkqty)){ $mqty = $row->quantity_procured; $gqty = $gqty + $mqty; } if($qty <= $gqty){ echo 1; }else{ echo 2; } }else{ echo ''; }
原文:https://stackoverflow.com/questions/19588849
满意答案
/部分对! 细化与图像一起使用。 该对与x / y坐标相关,如
>> img: load %image.png == make image! [519x391 #{ 1D2F9F1D2F9F1C2E9E1C2E9E1B2D9D1B2D9D1B2D9D1B2D9D1D2F9F1C2E9E 1A2C9C192B9B192B9B1A2C9C1B2D9D1C2E9E1D2EA01... >> copy/part img 2x2 == make image! [2x2 #{ 1D2F9F1D2F9F1D2F9F1D2F9F }]
这里是一个例子/部分系列的例子! 工作中
>> s: [a b c d e f g] == [a b c d e f g] >> ser: skip s 3 == [d e f g] >> copy/part s ser == [a b c]
The /part pair! refinement works with images. The pair relates to the x/y coordinates as in
>> img: load %image.png == make image! [519x391 #{ 1D2F9F1D2F9F1C2E9E1C2E9E1B2D9D1B2D9D1B2D9D1B2D9D1D2F9F1C2E9E 1A2C9C192B9B192B9B1A2C9C1B2D9D1C2E9E1D2EA01... >> copy/part img 2x2 == make image! [2x2 #{ 1D2F9F1D2F9F1D2F9F1D2F9F }]
And here an example how /part series! is working
>> s: [a b c d e f g] == [a b c d e f g] >> ser: skip s 3 == [d e f g] >> copy/part s ser == [a b c]
相关问答
更多Rebol R3有哪些配置文件以及它们是如何加载的?(What configuration files are there for Rebol R3 and how are they loaded?)
Rebol网格控制(Rebol grid control)
在Rebol 2中,对象上的位置PICK是什么,以及等效的Rebol 3是什么?(What does positional PICK on an object do in Rebol 2, and what's the equivalent Rebol 3?)
Rebol REPL Multi line if语句(Rebol REPL Multi line if statement)
在REBOL 3中复制/部分配对(copy/part with pair in REBOL 3)
在Rebol中刷新图像(Refresh an image in Rebol)
如何在rebol中组织代码?(How to organize code in rebol? [closed])
Red中的REBOL方法(REBOL methods in Red)
rebol解析问题(rebol parse problem)
REBOL元编程问题(REBOL metaprogramming questions)
相关文章
更多AJAX问题
Guava集合工具类-Table接口映射处理
Solr PHP support
HDFS导出数据到HBase的ROW VALUE设置tricks
my php & mysql FAQ
Guava学习笔记:Guava新集合-Table等
Ajax 异步传输
ajax数据安全的问题
Ajax彻底研究-视频教程
《自学it网-PHP公益培训-YY直播中[24小时供源]-(4月9日更新)-PHP项目实战 mysql smarty thinkphp javascript ajax jquery linux lamp》[WMV]
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!