我创建了一个带有用户输入的html表单,并且应该返回相关的发票。我没有收到任何错误,我已经检查了我的HTML代码,以确保isset的条件是正确的。我还在PHPAdmin中测试了查询(它返回了我要求的信息)。但是,发票不会打印到屏幕上,也不会出现错误或PHP代码。我在屏幕上唯一得到的是标题(html未显示)和超链接(html未显示)。下面是相关的PHP代码部分。提前谢谢。
if( isset($_POST["submit"] )) {
if (!($stmt =$mysqli->prepare("SELECT DISTINCT INVOICE.date, CUSTOMER.Name, CUSTOMER.Lname, CUSTOMER.Phone, CUSTOMER.Address, CUSTOMER.email, INVOICE.Invoice_num, INVOICE.Itm_num, INVOICE.Itm_Price, INVOICE.Discount, INVOICE.Total
FROM CUSTOMER, INVOICE
WHERE CUSTOMER.Phone = INVOICE.Cust_phone AND CUSTOMER.Lname = INVOICE.Cust_lname AND
(CUSTOMER.Name = ? OR CUSTOMER.Lname = ? OR INVOICE.date = ? OR INVOICE.Invoice_num = ? OR INVOICE.Itm_num = ?)
GROUP BY date;"))) {
print "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("sssis",$_POST['fname'], $_POST['lname'], $_POST['date'], $_POST['invoice_num'], $_POST['item_num'])) {
print "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
print "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->store_result();
if (!$stmt->bind_result($date, $Fname, $Lname, $Phone, $Address, $Email, $Invoice_num, $Item_num, $Itm_Price, $Discount,$Total)) {
print "Binding output parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if ($stmt->num_rows == 0){
print "No results were found for the following search <p>".$_POST['fname'].$_POST['lname'].$_POST['date'].$_POST['invoice_num'].$_POST['item_num']."</p>";
}
else {
print "<table border=2 cellpadding=4>
<tr bgcolor=white>
<th>Date</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Address</th>
<th>Email</th>
<th>Invoice #</th>
<th>Item #</th>
<th>Price</th>
<th>Discount (if applicable)</th>
<th>Total</th>
</tr>";
while ($stmt->fetch()) {
print "<tr><td>".$date."</td>
<td>".$Fname."</td>
<td>".$Lname."</td>
<td>".$Phone."</td>
<td>".$Address."</td>
<td>".$Email."</td>
<td>".$Invoice_num."</td>
<td>".$Itm_num."</td>
<td>".$Itm_Price."</td>
<td>".$Discount."</td>
<td>".$Total."</td></tr>";
}
print "</table>";
}
$stmt->free_result();
}
任何建议都将不胜感激。
答案 0 :(得分:1)
如果没有从您的代码打印,我猜想,根据isset
,$_POST["submit"]
未设置或者为空。
要验证这一点,请在if (isset(...))
之后立即发出回音。如果您没有看到回声,请检查您的$_POST
变量。它可能拼写错误,甚至作为GET请求而不是POST发送。