简体   繁体   English

如何设置对PHP文件和新HTML页面的表单操作?

[英]How to set form action to PHP file and new HTML page?

I'm just starting to learn PHP and built a simple pizza ordering site to take orders and submit it to my database. 我刚刚开始学习PHP,并建立了一个简单的比萨订购网站来接受订单并将其提交到我的数据库。 I want the order form to not only to POST the customer's order details, but also redirect to a new HTML page that takes customer's information. 我希望订单不仅要发布客户的订单详细信息,还要重定向到一个新的HTML页面,其中包含客户的信息。 Here's what I tried. 这是我尝试过的。

<form action="http://localhost/pizza/pizzaform.html" action="pizza.php" method="post">

Unfortunately, only the first form action seems to work. 不幸的是,只有第一个形式动作似乎起作用。 How is it possible to execute both of these?I have also pasted my pizza.php code below . 如何执行这两个步骤?我还在下面粘贴了pizza.php代码。

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;
}

?>

You should use one action, and redirect the user after the sql is done. 您应该使用一种操作,并在完成sql之后重定向用户。

From the php docs 从PHP文档

<?php
header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

You should try something like this 你应该尝试这样的事情

<form action="pizzaorder.php" method="post">

After the Oder insert into your database 在Oder插入数据库之后

 $success = $cnn->query($sql);
 if ($success) {
   header("Location:thankyou.php"); /* Redirect browser to thankyou*/
 } else {
   echo "Whoops! Looks like something went wrong";
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM