在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
2023-11-17 20:11

满意答案

/部分对! 细化与图像一起使用。 该对与x / y坐标相关,如

>> img: load %image.png 
== make image! [519x391 #{
1D2F9F1D2F9F1C2E9E1C2E9E1B2D9D1B2D9D1B2D9D1B2D9D1D2F9F1C2E9E
1A2C9C192B9B192B9B1A2C9C1B2D9D1C2E9E1D2EA01...
>> copy/part img 2x2
== make image! [2x2 #{
1D2F9F1D2F9F1D2F9F1D2F9F
}]

REBOL /查看图像数据类型

这里是一个例子/部分系列的例子 工作中

>> 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
}]

REBOL/View Image Datatype

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?)

目前user.r已被弃用为安全风险。 应该有一种方法可以实现这种方法......但是还没有人开始研究它。 见http://chat.stackoverflow.com/transcript/291?m=9149463#9149463 Currently user.r deprecated as a security risk. There is supposed to be a dialected method for this to happen .. but no one has starte...

Rebol网格控制(Rebol grid control)

根据您的需要准确。 Brett的数据网格有点基础。 例如,它本身不处理滚动条。 Henrik已经完成了具有大量功能的列表视图。 也许它可以作为你的选择: list-view 。 但是同一作者的VID扩展工具包也有不同的列表样式部分。 这是列表文档。 所有这些都是针对Rebol2的。 Depending what you need exactly. Brett's datagrid is a bit basic. For example, it does not handle scrollers b...

在Rebol 2中,对象上的位置PICK是什么,以及等效的Rebol 3是什么?(What does positional PICK on an object do in Rebol 2, and what's the equivalent Rebol 3?)

a)构建构建对象而不评估规范块。 这意味着规范是some [set-word! any-type!] some [set-word! any-type!]形式(如果你使用另一个对象的主体,它总会是这样)。 构建/使用第二个对象( mumble )作为原型。 b)对象操作似乎已经改变如下: i) first object被first object的words-of object替换 ii) second object被替换values-of object的values-of object iii) ...

Rebol REPL Multi line if语句(Rebol REPL Multi line if statement)

在Rebol 2 REPL中,这应该可行。 在第一行之后,提示应该变为“继续提示”: >> if size [ [ ;<cursor here> 在Rebol 3中,REPL目前(2013-02)不支持多行表达式。 In the Rebol 2 REPL, this should just work. After the first line, the prompt should change into a "continuation prompt": >> if size [ [ ...

在REBOL 3中复制/部分配对(copy/part with pair in REBOL 3)

/部分对! 细化与图像一起使用。 该对与x / y坐标相关,如 >> img: load %image.png == make image! [519x391 #{ 1D2F9F1D2F9F1C2E9E1C2E9E1B2D9D1B2D9D1B2D9D1B2D9D1D2F9F1C2E9E 1A2C9C192B9B192B9B1A2C9C1B2D9D1C2E9E1D2EA01... >> copy/part img 2x2 == make image! [2x2 #{ 1D2F9F1D2F9F1D2...

在Rebol中刷新图像(Refresh an image in Rebol)

您可以使用set-face更新图像的方式 将刷新按钮行更改为: btn "Refresh" [set-face b img2] 或者,如果您手动更改脸部的窗格,则可以使用show (即show b ) The way you can update an image is by using set-face Change the refresh button line to: btn "Refresh" [set-face b img2] Alternatively if you are m...

如何在rebol中组织代码?(How to organize code in rebol? [closed])

我知道的一些主题使用我的include.r ,现在在Apache 2.0下发布。 它不是模块系统,但您可能会发现它很有用。 Some subjects I know use my include.r, released under Apache 2.0 now. It is not a module system but you may find it useful.

Red中的REBOL方法(REBOL methods in Red)

在Rebol中, rejoin和to-word都是更多元素函数的快捷方式。 在Red(从版本0.6.0开始),这两个功能都可用: >> to word! "foo" == foo >> to word! append "foo" "bar" == foobar 在附加之前复制第一个字符串可能更好,但这应该足以创建动态字。 In Rebol, both rejoin and to-word are both shortcuts for more elemental functions. In Re...

rebol解析问题(rebol parse problem)

你正在寻找'撰写 >> parse "aaa" compose [ some (charset [#"a" #"b"] ) ] == true You're looking for 'compose >> parse "aaa" compose [ some (charset [#"a" #"b"] ) ] == true

REBOL元编程问题(REBOL metaprogramming questions)

这有几种方法: x: :print ;; assign 'x to 'print x "hello world" ;; and execute it hello world blk: copy [] ;; create a block append blk :print ;; put 'print in it do [blk/1 "hello world"] ;; execute first entry in the ...

相关文章

更多

AJAX问题

我的问题是这样 两个下拉框 区县 &lt;/td&gt; &lt;td width=&quot; ...

Guava集合工具类-Table接口映射处理

System.out.println("Emp&nbsp

Solr PHP support

Solr PHP support Contents Solr PHP support ...

HDFS导出数据到HBase的ROW VALUE设置tricks

在做Hadoop的编程时,有时会用到HBase,常常涉及到把HDFS上面的数据导入到HBase中,在这 ...

my php & mysql FAQ

php中文字符串长度及定长截取问题使用str_len(&quot;中国&quot;) 结果为6,php ...

Guava学习笔记:Guava新集合-Table等

  Table   当我们需要多个索引的数据结构的时候,通常情况下,我们只能用这种丑陋的Map&lt; ...

Ajax 异步传输

function getData(){ var url = &quot;Show.do?dh=1&q ...

ajax数据安全的问题

我在一个网页中使用jquery里的ajax函数做ajax效果,一般会按照参数格式填写url(还有其他参 ...

Ajax彻底研究-视频教程

PHP学习一本通.pdf PHP公益培训第3部-064-ajax长轮询完成咨询功能.wmv PHP公益 ...

《自学it网-PHP公益培训-YY直播中[24小时供源]-(4月9日更新)-PHP项目实战 mysql smarty thinkphp javascript ajax jquery linux lamp》[WMV]

中文名: 自学it网-PHP公益培训-YY直播中[24小时供源]-(4月9日更新)-PHP项目实战 m ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本