Jpower24 Posted March 16, 2007 Share Posted March 16, 2007 Its for a web programming class, I have to design an index page that displays the products. I'm done that which was simple enough. Now I have to make an order form. Build another XHTML page and using PHP, determine the following things: a) That the visitor did indeed select something to purchase. b) Calculate the price of the purchase (factoring in PST and GST). c) Output a friendly message thanking them for their purchase. Include a full description of what they bought, the price and when they can expect their order. d) Valid XHTML for your order form and the thank you message. I really need some help here Ill put up the xhtml code first then the php. I dont know how to work them into eachother. I dont know how I would echo "you bought xxinches waterpipe" when that part is in the order form. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="styles.css" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <h1>Order Form</h1> <form action="orderform.php" method="post"> <h2>Color:</h2> <select name="color"> <option value="Blue Transparent ">Blue Transparent </option> <option value="Green Transparent ">Green Transparent )</option> <option value="Yellow Transparent ">Yellow Transparent </option> <option value="Red Transparent ">Red Transparent </option> </select> <h2>Size</h2> <select name="Size"> <option value=" 8 inches ">8 inches </option> <option value="12 inches ">12 inches</option> <option value="24 inches ">24 inches</option> <option value="36 inches ">36 inches</option> </select> <h2>Quantity</h2><input type="text" name="Quantity" value="1"> <h2>Name</h2><input type="text" name="Name" value=""> <h2>Address</h2><input type="text" name="Address" value=""> <h2>City</h2><input type="text" name="City" value=""> <h2>Province</h2><input type="text" name="Province" value=""> <label for="cost"><h2>Cost: $</h2></label> <input type="text" name="cost" id="cost" value="Total before taxes/shipping" /> <input type="submit" value="Calculate GST" /> <input type="hidden" name="recipient" value="JPOWER24@hotmail.com"> <input type="hidden" name="redirect" value=""> <input type="hidden" name="required" value=""> <input type="hidden" name="env_report" value="REMOTE_HOST, HTTP_USER_AGENT"> </form> the php code <?php if(isset($_POST['cost']) && ($_POST['cost'] != 0)){ $cost = $_POST['cost']; $gst = $cost*0.06; $pst = $cost*0.08; $ship = 10; $cost += $gst + $pst +$ship; echo "<h1>Total Cost: $".$cost."</h1>"; }; ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 Sounds like you might want to read your notes or perhaps the text book, I am sure they provide examples. Quote Link to comment Share on other sites More sharing options...
shaunrigby Posted March 16, 2007 Share Posted March 16, 2007 Depending on what you want to output, because you are using the POST Method in your form, you would use $_POST['variable]', where variable is what you have defined in your form, such as <select name="Size"> So, in your example, if say, for example, a customer selects 12 inches of pipe, in PHP you would type: <?php print "You have purchased, " . $_POST['Size'] . " of pipe."; ?> Quote Link to comment Share on other sites More sharing options...
Jpower24 Posted March 16, 2007 Author Share Posted March 16, 2007 so when I put Size in the form here <select name="Size"> php recognizes those values. more or less meaning if I did echo ' you purchased .$size pipe ' it would come out you purchased 12 inches pipe while if I changed <option value="12 inches ">12 inches</option> to <option value="12">12 inches</option> I could rewrite the above as echo ' you purchased .$size inches pipe ' Quote Link to comment Share on other sites More sharing options...
shaunrigby Posted March 16, 2007 Share Posted March 16, 2007 Yes that is correct, however i noticed something in your last post echo ' you purchased .$size inches pipe ' if $size is defined as $size = $_POST['Size']; then this will work, if not, you would use echo ' you purchased ' . $_POST['Size'] . ' inches pipe ' Quote Link to comment Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 It really sounds like you need to read the book. Especially to get the syntax correct. Reading is key. www.php.net is a great resource also. Quote Link to comment Share on other sites More sharing options...
shaunrigby Posted March 16, 2007 Share Posted March 16, 2007 Google is also your friend Quote Link to comment Share on other sites More sharing options...
Jpower24 Posted March 16, 2007 Author Share Posted March 16, 2007 Perfect so then in adding up the total cost I could go $ship= $size*0.2 $ship representing shipping and $size*0.2 is just saying that shipping will be 20% of length, inches to dollars. <?php if(isset($_POST['cost']) && ($_POST['cost'] != 0)){ $cost = $_POST['cost']; $size = $_POST['Size']; $gst = $cost*0.06; $pst = $cost*0.08; $ship = $size*0.2 $cost += $gst + $pst +$ship; echo "<h3>You've purchased .$size inches of pipe at a total cost of $.$cost , thanks for choosing....</h3>"; }; ?> assuiming that is right just one more thing has me puzzled. the <form action ="____" > I believe thats where you tell the form where to go. So do i tell it to go where the php file is such as form action="orderform.php or do i just put the php code in the web page itself and tell the form to go somewhere else? Quote Link to comment Share on other sites More sharing options...
interpim Posted March 16, 2007 Share Posted March 16, 2007 either way will work... different methods for each though Quote Link to comment Share on other sites More sharing options...
shaunrigby Posted March 16, 2007 Share Posted March 16, 2007 To configure wer the form would post/get variables to would be defined in the action part yes, i dnt really understand what you mean with the cost, are you wanting to get the total cost of everything? or wat? please elaborate... Quote Link to comment Share on other sites More sharing options...
Jpower24 Posted March 16, 2007 Author Share Posted March 16, 2007 yea the cost could actually be replaced with total it might make it easier to understand for you. But I'm pertty sure i got this right. It just gets the total cost, which is, the amount they enter is inputted into the php code, and is then times by .06 .08 (tax) and then .2 (shipping). then when i hit the get total button I want it to give that value Quote Link to comment Share on other sites More sharing options...
Barand Posted March 17, 2007 Share Posted March 17, 2007 You have a single cost field. Does this mean that if they order 8 inches or 36 inches the price is the same for both? Or is it a cost per inch, in which case you need to multply the cost by the size. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.