我正在尝试从customer
一张桌子到另一张桌子上获取客户ordertracking
ID。-但是- 订单的添加还需要它从订单中获得的产品信息。我尝试了几种方法,但无法使其正常工作。还有一件奇怪的事:
//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);