I’ve created an html form that take user input and is supposed to return the relevant invoice. I’m not getting any errors and I’ve checked my html code to make sure the conditions are correct for isset. I’ve also tested the query in PHPAdmin (it returns the info I’m asking for). However, the invoice is not printing to the screen nor are errors or PHP code. The only thing I get on the screen is the title (html not shown) and hyperlinks (html not shown). Below is the section of PHP code that is relevant. Thanks in advance.
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();
}
Any suggestions would be greatly appreciated.
When nothing prints from your code, I would guess that, according to
isset, either$_POST["submit"]is not set or it is null.To verify this, put an echo right after
if (isset(...)). If you don’t see the echo, check for your$_POSTvariable. It might be misspelled or even sent as a GET request instead of POST.