I have a restaurant pizzeria and I want to input in my mysql database the order of my clients, but I am having a problem how to input more than a type of pizza.
I am using a checkbox to select the items then go to this code:
<form id="detalhesdopedido" action="formadepagamento.php" method="post">
<?php
if (isset($_POST['submit'])) {
echo"<table id='t02'>
<tr>
<th width='15%'>Quant</th><th width='40%'>Produtos </th><th width='15%'>Total</th>
</tr>";
$total = 0;
if (isset($_POST['ch1'])) {
echo "<tr><td>";
echo $_POST['qt1'] ;
echo"</td>";
echo "<td> Produto 1 </td>";
echo "<td>";
echo $_POST['qt1'] * 10 ;
echo"</td></tr>";
$total += $_POST['qt1'] * 10;
}
if (isset($_POST['ch2'])) {
echo "<tr><td>";
echo $_POST['qt2'] ;
echo"</td>";
echo "<td> Produto 2 </td>";
echo "<td>";
echo $_POST['qt2'] * 20.30 ;
echo"</td></tr>";
$total += $_POST['qt2'] * 20.30;
}
if (isset($_POST['ch3'])) {
echo "<tr><td>";
echo $_POST['qt3'] ;
echo"</td>";
echo "<td> Produto 3 </td>";
echo "<td>";
echo $_POST['qt3'] * 30 ;
echo"</td></tr>";
$total += $_POST['qt3'] * 30;
}
if (isset($_POST['ch4'])) {
echo "<tr><td>";
echo $_POST['qt4'] ;
echo"</td>";
echo "<td> Produto 4 </td>";
echo "<td>";
echo $_POST['qt4'] * 40.50 ;
echo"</td></tr>";
$total += $_POST['qt4'] * 40.50;
}
if (isset($_POST['ch5'])) {
echo "<tr><td>";
echo $_POST['qt5'] ;
echo"</td>";
echo "<td> Produto 5 </td>";
echo "<td>";
echo $_POST['qt5'] * 50.45 ;
echo"</td></tr>";
$total += $_POST['qt5'] * 50.45;
}
echo "</table>";
echo "<div id='total'>Valor Total: " .$total. "</div>";
}
?>
<button id="finalizar" type="submit">Finalizar Pedido</button>
</form>
How do I insert this into the mysql database?
I want it to appear like this on the database:
cliente /order/quantity/total price
alex/ produto 1 , produto 2/ 2 , 3/ 34.50
or does someone know a better way to show me?
There is no information about the structure of your database.
What you can do is to have a few tables like this -
Product(_id, productName, price);
Order(_id, clientName, productIds, qtys, total);
For the Order table, productIds will be a foreign key to Product(_id) and under it, you can store the productIds for all the ordered products separated by a comma. Same for qtys.
Another approach can be
Order(_id, clientName, productId, qty, total, timestamp);
where you can retrieve the records using the where and order by clauses