1

我有一个任务,我不能将 mySQL 用于汽车订购系统。

我被要求输入品牌、型号、颜色、选项,然后将它们全部显示在评论和完整页面中。

我必须在一个单独的页面中创建它们。例如(品牌:丰田)单击下一步,打开(型号:凯美瑞)单击下一步等。我的问题是当我必须将它们分开时。我只保留上一页的数据。

有人可以帮忙吗。我会提供一些代码。

询问汽车品牌:(order.html)

<form action="order_model.html" method="post">
  Brand:
  <input type="text" name="brand" size="20" maxlength="20">
  <input type="submit" value="Next >>">
</form>

询问型号:(order_model.html)

<form action="process.php" method=post>
  Model:
  <input type="text" name="model" size="20" maxlength="20">
  <input type="submit" value="Next >>">
</form>

PHP 文件: (process.php)

<?php
$brand = $_POST['brand'];
$model = $_POST['model'];
?>

<p>Review and Complete Your Order:</p>

 //I shortened the code, these used to be in tables. 
Make: 
<?php echo $brand.' '; ?> //Does not display
Model: 
<?php echo $model.' '; ?> //Displays
<p><input type="submit" value=" Complete Order "></p>

当它显示 process.php 时,它只显示模型。我需要它来显示品牌和型号,在我弄清楚如何做之后我可以做颜色和其余的事情。

4

2 回答 2

3

将 order_model.html 更改为:

<form action="process.php" method=post>
 Model:
  <input type="text" name="model" size="20" maxlength="20">
  <input type="hidden" name="brand" value="<?php if(isset($_POST['brand'])) echo  $_POST['brand']; ?>">  
  <input type="submit" value="Next >>">

</form>

更新:正如 Phas1c 所指出的,除了这些更改之外,您可能还希望将 order_model.html 重命名为 order_model.php 并对 order.html 进行相应的更改。您可能还想将该文件重命名为 order.php 以获得更好的一致性。

于 2013-07-22T16:23:53.707 回答
1

使用 session 在整个工作流程中维护您的表单值。从第一个表格帖子

<form action="order_model.html" method="post">
  Brand:
  <input type="text" name="brand" size="20" maxlength="20">
  <input type="submit" value="Next >>">
</form>

您将品牌保存到会话中$_SESSION['brand'] = $_POST['brand']

并从过程中保存模型$_SESSION['model'] = $_POST['model'];

然后,您可以根据unset需要在最终确定订单和变量的地方使用它。

于 2013-07-22T16:24:57.600 回答