嗨,我有一个 ajax 请求,我正在通过 ajax 向 php 文件发送一些请求,并且该请求正在生成一个结果,到目前为止一切正常,但现在我想对我的结果进行一些验证。我在动态添加的表行上执行此操作,因此如果未满足验证,则不允许添加新行,但在验证后仍会添加行,任何人都可以帮助解决我的问题,谢谢这是我的代码
$("#savetodb").removeAttr("disabled");
var vendor = $("#sub_vendor_id"+rowcount+">option:selected").val();
var product = $("#prodid_"+rowcount).val();
var productname = $("#prod_"+rowcount).val();
var vouchdt = $("#dateinfo").val();
var qty = $("#quantity_"+rowcount).val();
var amt = $("#amount_"+rowcount).val();
$.get("../model/check_product_with_invoice_number.php", { invno : invoice, product : product, vendor : vendor, date : vouchdt, quantity : qty, amount : amt }, function (result) {
if(result == "") {
alert(productname+" Does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
}
if(result == 2) {
alert("Quantity "+ qty +" for "+productname+" does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
}
if(result == 3) {
alert("Amount "+amt +" For "+productname+" does not exist for invoice number "+id);
$("#savetodb").attr("disabled", "disabled");
}
if(result !=='' && result !==3 && result !==2){
$("#savetodb").removeAttr("disabled");
append_row('enable remove','',prods,unitid,unitcode);
}
});
这是我的 php
$code = mysql_real_escape_string($_GET["invno"]);
$vendor = mysql_real_escape_string($_GET["vendor"]);
$product = mysql_real_escape_string($_GET["product"]);
$vouchdt = mysql_real_escape_string($_GET["date"]);
$amt = mysql_real_escape_string($_GET["amount"]);
$qty = mysql_real_escape_string($_GET["quantity"]);
$chkquantity = mysql_query("SELECT * FROM `gc_procurement_daily_detail` WHERE quantity_procured='".$qty."'
AND product_id='".$product."' AND sub_vendor_id='".$vendor."'")or die(mysql_error());
if(mysql_num_rows($chkquantity)> 0){
$chkamt = mysql_query("SELECT * FROM `gc_procurement_daily_detail` WHERE procured_detail_amount='".$amt."'
AND product_id='".$product."' AND sub_vendor_id='".$vendor."' AND quantity_procured='".$qty."'")or die(mysql_error());
if(mysql_num_rows($chkamt)>0){
$chkinvoice = mysql_query("SELECT a.*, b.* FROM `gc_procurement_daily_detail` a, `gc_procurement_daily_summary` b
WHERE a.sub_vendor_id='".$vendor."' AND a.product_id='".$product."' AND
a.quantity_procured='".$qty."' AND a.procured_detail_amount='".$amt."' 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_query());
$minv = mysql_fetch_object($chkinvoice);
$fininv = $minv->invoice_number;
if($code == $fininv){
echo 1;
exit;
}else{
echo '';
exit;
}
}else{
echo 3;
exit;
}
}else{
echo 2;
exit;
}