我刚开始学习PHP并构建了一个简单的披萨订购网站来接受订单并将其提交到我的数据库。我希望订单不仅可以发布客户的订单详细信息,还可以重定向到获取客户信息的新HTML页面。这是我尝试过的。
<form action="http://localhost/pizza/pizzaform.html" action="pizza.php" method="post">
不幸的是,只有第一个表格动作似乎有效。如何执行这两项操作?我还在下面粘贴了我的pizza.php
代码。
PHP
<?php
require("pizzacnn.php");
$query = "SELECT * FROM `customers`";
$query2 = "SELECT * FROM `inventory`";
if ($query_run = (mysqli_query($cnn,$query))){
echo "tables found";
$sql = "INSERT INTO customers (name,address,phone_number, money,feedback) VALUES ('{$_POST['name']}','{$_POST['address']}','{$_POST['phone']}','{$_POST['money']}','{$_POST['feedback']}')";
}
else if ($query2_run = (mysqli_query($cnn,$query2)){
$sql = "INSERT INTO inventory (toppings,number) VALUES ('{$_POST['topping']},'{$_POST['number']}')";
}
if ($cnn->query($sql)===TRUE){echo "record created succcessfully";}
else {
echo "Error: ".$sql."<br>".$cnn->error;
}
?>
答案 0 :(得分:3)
您应该使用一个操作,并在sql完成后重定向用户。
来自php docs
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
答案 1 :(得分:1)
你应该尝试这样的事情
<form action="pizzaorder.php" method="post">
将Oder插入数据库后
$success = $cnn->query($sql);
if ($success) {
header("Location:thankyou.php"); /* Redirect browser to thankyou*/
} else {
echo "Whoops! Looks like something went wrong";
}