# Web Design/Generating a receipt with PHP

Web Design → Generating a receipt with PHP
This page is part of the Web Design project. :
Once your basic response and email are all happening, and you're feeling a bit more confident with your first PHP pages, it's a good time to start learning a bit more about PHP variables and control structures! But before moving on from here, please make sure that your response.php currently:
* Responds personally to the user
* Includes the details of the product selected by the user (its name and its price)
* includes the billing information for the user.

## Adding up the total

If a visitor to your site indicates that they want to buy 5 T-shirts at $15 each, we need to let them know what their total comes to! To do this, we'll need to create a variable.
You might have noticed that variables in PHP always have a dollar sign ($) in front of them. Here are a few examples:
Can you guess why the apostrophe (') in $string2 has a back-slash (\) in front of it?
We need to create a new variable called $total in our response.php. Initially we'll set it to 0 like this:
but your challenge is to print out the total for the order when your form is submitted!
If your visitor submits your form indicating that they want to buy 5 T-shirts at $15 each, what would the total be? Fill in the blanks in the following:
In our situation, we don't know how many items our visitors would like to buy until they submit the form. See if you can modify the code above to use your $quantity variable instead of '5'. Add this line to your code and print it out on your receipt.
No peaking at the solution until you have had a good attempt yourself!
You should already have a variable called $quantity in your response.php that takes the value from your form. For example, if your form includes the input field:
then your response.php would create the variable $quantity like this:
Let's pretend that whatever product of service that your form is selling costs $15 per item, then calculating the total and printing it out can be done as follows:
Extra: So you don't need to change your code everywhere when you put the price up to $20, create another variable $tshirt_price (or something relevant to your own form), set it equal to 15 and then use this variable in your calculation instead of the constant number 15.

## Including postage in the total

Now that we've calculated the total for our order, we need to include a postage fee! The following exercise will help you along the way!
To include the postage fee, we need to take our current total and add $20 to it, and then inform our customer of the total including postage.
You'll need to add the following code (after filling in the blanks) to calculate the new total:
and then include a new print statement that informs your visitor of the total including postage!
Sorry - hope to have time soon. When you get the answer, how about adding it in here!

## Free delivery for bulk buys

Let's say you decide it would be good for business if you offer free delivery if customers buy more than 6 items.
Your pseudo-code should look something like this:
You might want to take a look at if-statements in the PHP manual or Free2Code's explanation of if-statements to get an idea of how if-statements work in PHP (they're nearly identical to if-statements in JavaScript).
TO DO: Exercise with solution

## Discount if you spend over $200

Finally, if your customers spend over $200 (modify to suit your needs), they get a 10% discount.
Again your pseudo-code should look like...