customer
テーブルからテーブルへの顧客IDを取得しようとしていordertracking
ます。-しかし- 注文の追加には、注文フォームから取得した製品情報も必要です。いくつかの方法を試しましたが、うまくいきません。また、別の奇妙なこと:
//connect to database
$connection = mysql_connect("localhost","root","") or die ("Can't connect");
mysql_select_db("shoppingcart", $connection) or die ("Can't connect");
//check if already customer
$result = mysql_query("SELECT * FROM customer WHERE email='$email'");
$rows = mysql_num_rows($result);
if ($rows)
{
echo '<br>Welcome back ' . $name .' '. $surname. '<br>';
}
else
{
//if new customer, add to database
$customer = "INSERT INTO customer (customerid, name, surname, email, city, GETalcode, phonenumber) VALUES ('', '$name', '$surname', '$email', '$city', '$postalcode', '$phonenumber')";
if (!mysql_query($customer,$connection))
{
die('Error: ' . mysql_error());
echo "Sorry, there was an error";
}
echo "New customer added" . "<br />";
echo '<br>Welcome as our new customer ' . $name . ' '. $surname;
mysql_close($connection);
}
//connect to database
$connection = mysql_connect("localhost","root","") or die ("Can't connect");
mysql_select_db("shoppingcart", $connection) or die ("Can't connect");
//get customer id
????????????????????
//add new order
$ordertracking = "INSERT INTO ordertracking (orderid, customerid, productid, brand, model, price, amount, totalcost) VALUES ('', '$customerid', '$productid', '$brand', 'model', 'price', 'amount', 'totalcost')";
if (!mysql_query($ordertracking,$connection))
{
die('Error: ' . mysql_error());
echo "Sorry, there was an error";
}
echo "New order added" . "<br />";
mysql_close($connection);