PHP Order form

Hi everyone,

I’m looking for a point in the right direction. I just about to start my biggest coding project yet. (A Simple PHP Order form).

The client has suggested that they want a form for users to enter a reference code (from a catalog) of a product type how many items they want. It will generate a sub total. And if the total is over a certain amount discount will be given.

The form will also have the regular form fields as well. e.g Name, email, address etc…

Then all this will post to a email. I’ve created contact form scripts before. But is there any links or tutorials that could help me do this or even point me in the right direction.

Thanks for all the help


It seems to be pretty simple. The core of it would be something like:

// get and sanitize submitted values
// ...

// calculate the sub total
$itemPrice = getPriceByRefCode($refCode);
if ($quantity < 1) {
    $quantity = 1;
$subTotal = $itemPrice * $quantity;
$total = $subTotal;

// handle discount
if ($subTotal >= $config['discountThreshold']) {
    $discount = $subTotal * $config['discountPercentage'] / 100;
    $total = $subTotal - $discount;

// show the result
// ...

where getPriceByRefCode is a function that retrieves the price from the database, and $config is where standard configuration info is stored, perhaps being read in earlier from a config file with something like parse_ini_file()

Thanks Paul for the reply and for this script. That put’s me in the right direction. But the thing is There is actually no database.

The user will be required to type in a reference code, a price and quantity in a text box which will generate a total.

And when this has been filled out along with their name and address details, it is sent in an email and then the client will cross reference their details and make sure it’s a genuine enquiry.

Does this make it easier to do because there is no database involved? Simple mathematics in theory.

Yes, the only change to the above code would be in removing the $itemPrice line, since you would have obtained it beforehand from the form.