1- I have inserted products in the table cart (and it works)
2- I identify if is a new or old customer(and it works)
3- I insert the new customer in the table customers or I update the new info of an existed customer. (and it works) I write here the code simplified.
I suppose that now I need to insert in the table cart, row customer_id, the id just created in the table customers (I mean the session id of table customers) How can I do that?
if(isset($_POST["continue"])){
mysql_query("INSERT INTO customers (name)
VALUES ('$_POST[name]')")
or die("error:".mysql_error());
header("Location:step4.php");
}else if (isset($_POST["update"])) {
mysql_query("UPDATE customers
SET name='$_POST[name]'
WHERE mail='$_SESSION[mail]'")
or die("error:".mysql_error());
header("Location:step4.php?updated");
}
I tried and it does not work this:
mysql_query("INSERT INTO cart (customer_id)
SELECT'$_SESSION['id']'
FROM customers")
Use the
mysql_insert_id()as documented here: http://php.net/manual/en/function.mysql-insert-id.php