php - 表单提交变量未检索数据

标签 php html mysql fpdf

虽然我在这里找不到该问题的解决方案,但我想发布此内容。当尝试从表单提交的变量 $receiptNo 检索数据时,它不起作用。

sales.php

<input name="txtReceiptNo" type="text" id="txtReceiptNo" size="10" value="<?php $receiptNo = mysqli_fetch_row(mysqli_query($connection,"SELECT max(sales_id)+1 FROM sales")); echo $receiptNo[0];?>" readonly />    

销售收据.php

if(isset($_POST['txtReceiptNo'])){ $receiptNo = $_POST['txtReceiptNo']; } 

$result=mysqli_query($connection,"SELECT I.item_name, S.qty, S.unit_price, S.amount, S.date,S.receipt_no, S.discount, U.username 
FROM sales S
INNER JOIN items I ON S.item_id=I.item_id
INNER JOIN users U ON S.user_id=U.id
WHERE S.receipt_no=$receiptNo");

但是,当尝试为 $receiptNo 提供数据库值(如下所示)时,它会检索数据。

$result=mysqli_query($connection,"SELECT I.item_name, S.qty, S.unit_price, S.amount, S.date,S.receipt_no, S.discount, U.username 
FROM sales S
INNER JOIN items I ON S.item_id=I.item_id
INNER JOIN users U ON S.user_id=U.id
WHERE S.receipt_no=324");

enter image description here

任何帮助将不胜感激。

fpdf 代码片段 (salesreceipt.php):

<?php 

if(!isset($_SESSION)) 
{ 
  session_start(); 
} 

if(isset($_POST[$receiptNo])){ $receiptNo = $_POST['txtReceiptNo']; } 

$result=mysqli_query($connection,"SELECT I.item_name, S.qty, S.unit_price, S.amount, S.date,S.receipt_no, S.discount, U.username FROM sales S INNER JOIN items I ON S.item_id=I.item_id INNER JOIN users U ON S.user_id=U.id WHERE S.receipt_no='$receiptNo'"); $receipt_no = $row['receipt_no']; 

$pdf->Cell(45,5,$receipt_no,0,0,'L',0);

$pdf->Cell(40,10,$receiptNo,1);

enter image description here

最佳答案

我找到了这个问题的解决方案。

调用PROCEED按钮时没有提交表单。只有一个 onclick 事件来打开一个窗口,如下所示:

<input type="submit" name="btnPrintReceipt" id="btnPrintReceipt" value="PRINT &amp; PROCEED" onclick="window.open('<?php echo BASE_URL?>reports/salesreceipt2.php','popup','width=1200,height=900'); return false;"/>

我改成这样:

<input type="button" name="btnPrintReceipt" id="btnPrintReceipt" value="PRINT &amp; PROCEED" onclick="printProceed(true, txtReceiptNo.value);resetformTotal();"/>

并添加了 ajax 调用。

function printProceed(isPrint, recordId){

              var listCustomer = document.getElementById("listCustomer").value;
              var txtReceiptNo = document.getElementById("txtReceiptNo").value;
              var staff = document.getElementById("staff").value;
              var discount = document.getElementById("discount").value;
              var txtSubTotal = document.getElementById("txtSubTotal").value;
              var txtGrossTotal = document.getElementById("txtGrossTotal").value;

              // Returns successful data submission message when the entered information is stored in database.
              var dataString = {listCustomer: listCustomer, txtReceiptNo: txtReceiptNo, staff: staff, discount: discount};
              if (listCustomer == ''|| txtReceiptNo == ''|| staff == ''|| discount == '') {
              salesitemsAddFail();
              } 
              else {

$.ajax({
       type: "POST",
       url: "/pms/includes/functions/sales_functions.php",
       data: dataString,
       cache: false,
       //includes/functions/sales_functions.php
       success:function(html){
            if(isPrint == true){
            printpdf(recordId,txtSubTotal,txtGrossTotal,discount);
        }
       }

                         //reload the sales datagrid once add the item details to temporary table (sales_temp)
                 //window.location.reload();
                 //refresh/update the sub total value when adding

       });

                  $('#list').trigger("reloadGrid",[{page:1}]);
                  $("#sub_total_div").load(location.href + " #sub_total_div");

}}

关于php - 表单提交变量未检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40847978/

相关文章:

PHP 5.3 似乎默认缺少 Intl 扩展名

PHP 函数定义,空参数

php - curl 同一服务器时找不到 404

javascript - document.getElementById ('l' ).value;不管用

html - 图库在刷新几毫秒后显示多行,但应该只显示一行

php - 如何在单个查询中获取拥有产品的嵌套类别?

java - 当 Docker 容器中的 Java MVC 应用程序尝试连接到另一个容器中的 MySQL 时出现表不存在错误

php - Docker PHP 和 FreeTDS - 在已知安装目录中找不到 freetds

javascript - 从子按钮单击中删除最近的元素

mysql - 如何从 Mysql 将图像显示到 Devexpress GridView/Devexpress Card View