I am having a problem adding this array in a mysql database someone could help me? i think the problem is to identify the id of the array to input into the database.
<html>
<title> Registro do Pedido </title>
<body>
<h2> REGISTRE O PEDIDO</h2>
<form action="teste1.php" method="post">
<p align = "left">
Product 1:<input type="text" name="product1" ></br></br>
Quantity:<input type="int" name="quantidade1" ></br></br>
price:<input type="text" name="price1" ></br></br>
Product 2:<input type="text" name="product2" ></br></br>
Quantity:<input type="int" name="quantidade2" ></br></br>
price:<input type="text" name="price2" ></br></br>
<input type="submit" value="Registrar Pedido">
</body>
i need to add a for a client more than one procut and describe each quantity and price so i can calculate the total price how can i do that?
<?php
$conn = new mysqli("localhost", "root", "", "teste");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$addproduct[1]=array(
'produto'=> '$_POST[product1]',
'quant'=>'$_POST[quantidade1]',
'price'=>'$_POST[price1]'
);
$addproduct[2]=array(
'produto'=> '$_POST[product2]',
'quant'=>'$_POST[quantidade2]',
'price'=>'$_POST[price2]'
);
$sql = "INSERT INTO produtos (produto, quantidade, preco)
VALUES ('$addproduto[][produto]', '$addproduto[][quant]', '$addproduto[][price]')";
?>
one to manyrelation. With one table, u simply need to add each array item with sameorder idwith quries in loop.