I have a menu page that selects menu items from a server table and I’ve added a quantity selection to that page. I’m using a form button place the order go to a confirmation page which I want to have insert the menu items into an order table and then display those items and quantity if the selected quantity is greater than 0. I think I may be having trouble with how to assign those menu items to a variable because I can’t even echo them. Here is the relevant portion of my menu page and the entire page. Any guidance would be greatly appreciated.
menu.php:
<?php $link = mysqli_connect("localhost","jmckenzi_jmckenz","mck3nzi3","jmckenzi_customer") or die("Error " . mysqli_error($link)); echo "<table border='1' cellpadding='1' cellspacing='1'>";
echo "<tr>";
echo "<th>Quantity</th>";
echo "<th>Name</th>";
echo "<th>Description</th>";
echo "<th>Spicy?</th>";
echo "<th>Price</th>";
echo "</tr> ";
//echo APPETIZERS to html table
$queryApp = “SELECT * FROM menu WHERE itemCat = ‘APPETIZERS’” or die(“Error in the consult…” . mysqli_error($link));
$resultApp = $link->query($queryApp);
echo “
echo"
echo (“
if ($resultApp->num_rows > 0) {
// output data of each row
while($row = $resultApp->fetch_assoc()) {
echo "<tr>";
printf ("<td align ='center'>
<select>
<option value='0' name='quantity'>0</option>
<option value='1' name='quantity'>1</option>
<option value='2' name='quantity'>2</option>
<option value='3' name='quantity'>3</option>
<option value='4' name='quantity'>4</option>
<option value='5' name='quantity'>5</option>
<option value='6' name='quantity'>6</option>
<option value='7' name='quantity'>7</option>
<option value='8' name='quantity'>8</option>
<option value='9' name='quantity'>9</option>
</select>
</td>");
echo "<td name='itemName'>" . $row["itemName"] . "</td>";
echo "<td>" . $row["itemDesc"] . "</td>";
echo "<td name='isSpicy' style='text-align:center'>" . $row["isSpicy"] . "</td>";
echo "<td name='itemPrice' style='text-align:right'>" .'$'. $row["itemPrice"] . "</td>";
echo "</tr>";
}
}
else {
echo "0 results";
}
echo "</div>";
//continued…
order.php:
<?php $itemPrice = $_REQUEST['itemPrice']; //Retrieve data from form and store as variables $quantity = $_REQUEST['quantity']; $itemName = $_REQUEST['itemName']; include "scripts/database_connection.php"; $query = "INSERT INTO order(itemPrice,quantity,itemName) VALUES('$itemPrice','$quantity','$itemName') WHERE '$quantity' > 0"; $result = mysqli_query($link, $query); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $last_inserted_id = $link->insert_id; $affected_rows = $link->affected_rows; echo("Last Inserted Id: ". $last_inserted_id ); echo("Affected rows: " . $affected_rows); echo("Successfully added to the database:"); echo("Price: | {$itemPrice} |
Quantity: | {$quantity} |
Item: | {$itemName} |