虽然我在这里找不到该问题的解决方案,但我想发布此内容。当尝试从表单提交的变量 $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");
任何帮助将不胜感激。
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);
最佳答案
我找到了这个问题的解决方案。
调用PROCEED
按钮时没有提交表单
。只有一个 onclick
事件来打开一个窗口,如下所示:
<input type="submit" name="btnPrintReceipt" id="btnPrintReceipt" value="PRINT & 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 & 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/