PHP order form processing (newbie)

Hello all,

  1. I’m in the midst of creating a small ecommerce, and given that I’ve only started studying PHP a few days ago and thus only understand the very basics, I’m having quite a bit of trouble with the PHP scripting to process the order form (more specifically, with the pricing). The three variables that affect the total price are the following:

Delivery time: Under 24 hours = most expensive , 24-48 hours = little less expensive, 48-72 hours = little less expensive, 72-120 hours = little less expensive, 120-168 hours = little less expensive, over 168 hours (7 days) = least expensive

Product quality (sort of): For the purpose of this inquiry, think of it as “fair” (least expensive), “good”, “great”, “excellent” (most expensive).

Therefore, price per unit depends on the delivery time (on the y axis) and ‘product quality’ (on the x axis). So in the order form, if someone for instance selects 48-72 hours + great quality, the appropriate price should be calculated.

And finally, total price should be the price per unit multiplied by the number of units ordered.

How can this be done in PHP?

  1. In light of this, I’m also having trouble implementing the proper way to select the delivery date in the order form? Maybe 4 scroll down menus, including the day, month, year and approx hour of delivery? Any help here would be hugely appreciated as well.

  2. Based on the variables selected, I’d also like the total price to be updated on the order page in real time. I assume a client-side script like javascript would be necessary here?

  3. How do you make certain fields mandatory?

  4. After the order form has been properly completed, I’d like the client to be taken to the payment page (credit card or paypal).

That about sums it up. Thanks in advance for any scripts you can provide, or at least for pointing me in the right direction.

Hi there,

I’ve just scanned through quickly, but will give my two cents on a couple of your points.

You could try having:
$selected_time = trim(strip_tags($_POST[‘delivery_time’]));
$selected_qual = trim(strip_tags($_POST[‘quality’]));
$times = array(
“Under 24 hours” => 4.50
,“24-48 hours” => 3.75
$qualities = array(
“Fair” => 2.00
,“Good” => 3.00
,“Excellent” => 6.00
$price = $unit_price + $times[$selected_time] + $qualities[$selected_qual];

You will need to look into JavaScript and its involvement with AJAX & PHP - a JavaScript library called jQuery makes this sort of thing much easier.

Thanks for the quick response. Based on my limited understanding, that code looks like something that could work, if the price increases on a linear scale. But what if it doesn’t? For instance, what if I want the value you defined for under 24 hours to be greater for excellent quality than for fair quality? Is this possible?

ie: Fair => 2.00 , Under 24 hours (when selected with fair) => 4.50
Excellent => 6.00, Under 24 hours (when selected with excellent) => 10.00

I hope that makes sense.

Sponsor our Newsletter | Privacy Policy | Terms of Service