我试图让customerid从customer
表到ordertracking
表。 但是 - 订单的添加也需要它从订单表单获得的产品信息。我尝试了几种方法,但无法实现。 也是另一个奇怪的事情:从一个表到另一个表和订单添加PHP MYSQL
//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);
aaaaaaand .......它的作品!非常感谢你的脚本。我现在得到customerid在ordertracking。谢谢 – MOTIVECODEX