1

I want to follow the suggestions of this posts, but I have a problem of understanding: How to store complex product/order data in MySQL?

My php code looks like this:

if(isset ($_POST['submit'])) {
$payment = $_POST['payment'];
$shipping = $_POST['shipping'];
$order_person = $_POST['order_person'];
$total = $_POST['total'];
$status = $_POST['status'];
$q = "INSERT INTO orders(payment,shipping, order_person, total, status) VALUE(:payment, :shipping, :order_person, :total, :status)";
$query = $con->prepare($q);
$results = $query->execute(array(
":payment" => $payment,
":total" => $total,
":shipping" => $shipping,
":status" => $status,
":order_person" => $order_person
));
}

In my mysql database I have a row named "orders" where I have the fields:

  • orderID
  • date
  • order_person
  • shipping
  • payment
  • total
  • status

The order ID is generated with AUTO_INCREMENT. I created a second row named "order_details". Here I want to store my product details.

My problem is: I do not understand how exactly do I store the order ID into my row "orders" and also into "order details". I would be grateful about a detailed explanation. I am so confused. Thank you very much!

Community
  • 1
  • 1
user1242
  • 19
  • 1
  • 1
    possible duplicate of [How do I get the last inserted ID of a MySQL table in PHP?](http://stackoverflow.com/questions/1685860/how-do-i-get-the-last-inserted-id-of-a-mysql-table-in-php) – Epodax May 08 '15 at 13:46
  • First you said you created a row "orders" and "order_details". i think they are tables?Isn't it? – Alive to die - Anant May 08 '15 at 13:46

2 Answers2

0

Go on google and search mysqli_insert_id. This Function will give you the id which generated lately.

Jimmy
  • 76
  • 1
  • 9
0

If you are using pdo for database activity then use $con->lastInsertId() for the order ID which is created recently which you can use to insert in order details