1

I have an assignment where I cannot use mySQL for a Car Ordering System.

I am asked to get input for brand, model, color, options, then display them all in a review and complete page.

I have to create them all in an individual page. For instance (Brand: toyota) Click next, that opens (Model: camry) click next, etc.. My problem is when I have to separate them. I only retain the data from the previous page.

Can someone help. I'll provide some code.

Asking for Brand of car: (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>

Asking for model: (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 FILE: (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>

When It displays process.php, it only shows model. I need it to show brand and model, I can do the color and the rest after I figure out how to do one.

sora0419
  • 2,000
  • 9
  • 29
  • 55
GiBiT 09
  • 211
  • 6
  • 18

2 Answers2

3

Change order_model.html to this:

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

Update: as pointed out by Phas1c, in addition to these changes, you might also want to rename order_model.html to order_model.php and make corresponding changes to order.html. You might also want to rename that file to order.php for better consistency.

Rohit
  • 528
  • 5
  • 10
Maximus2012
  • 1,800
  • 2
  • 11
  • 15
  • 1
    Note: To do this, you may have to change `order_model.html` to `order_model.php` and adjust the `action` in the `order.html` form. – Phas1c Jul 22 '13 at 16:26
  • php can't submit form to an html file (containing php code) ? – Maximus2012 Jul 22 '13 at 16:27
  • Check out [this](http://stackoverflow.com/questions/11312316/how-do-i-add-php-code-to-html-files). You can include `html` in `.php` files but it doesn't appear possible to include ``tags inside of a `.html` file. – Phas1c Jul 22 '13 at 16:29
  • that makes sense. I'll update my answer to indicate that. It's always a good idea to have consistency in file names. – Maximus2012 Jul 22 '13 at 16:30
  • 1
    Your a lifesaver. That was frustrating me for the longest time. Yea I had to switch it to order_model.php. Thank you. – GiBiT 09 Jul 22 '13 at 16:30
1

use session to maintain your form values throughout the workflow. from the first form post

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

You save the brand to session like $_SESSION['brand'] = $_POST['brand']

and from process you save the model $_SESSION['model'] = $_POST['model'];

Then you can consume it where you finalize the order and unset the variables as necessary.

DevZer0
  • 13,069
  • 5
  • 24
  • 48