auspackuk Posted January 23, 2011 Share Posted January 23, 2011 Please how do i get my result displayed when i cilck on the calcluate price button. Hould i separate the codes to make sure my values are displayed accurately. The whole code is here: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Dynamic Page</title> </head> <body> <FORM METHOD = "POST" ACTION = "cal_price_form.php"> <FONT FACE ="Verdana" COLOR = "#1200FF"> <CENTER><B><H2> A program that calculates the cost of a product</H2></B></CENTER> </font> <br> <br> <?php //Print todays date on the screen $finddate= date("j-m-y"); echo "<h2>$finddate</h2>"; ?> Please type in the type of product <INPUT TYPE = "TEXT NAME" =" product_type" maxlength=10 SIZE =10 ><br> Please type in the name of the product <INPUT TYPE = "TEXT NAME" =" product_name" maxlength=35 SIZE =35 ><br> Please type in the cost of the product <INPUT TYPE = "TEXT NAME" ="original_price" MAXLENGHT = 5 SIZE = 5> <p> <INPUT TYPE ="Submit" VALUE="Calculate price"> <?php function calculate($original_price){ return $finalprice=($original_price * 0.16)+ $original_price; } echo"<br><h2><center>The type of product is:$product_type</center></h2>"; echo"<br><h2><center>The name of the product is:$product_name</center></h2>"; echo "<br><h2><center>The final price of the product is:".calculate($original_price)."</center></h2>"; ?> </body> </html> MOD Edit: . . . tags added. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 The markup and code are both a mess. Your form field markup is invalid, there are spaces between equals signs and values, quotes missing, etc. In the php code, (unless register_globals = On, which it should not) the variables are never assigned their values from the $_POST array, preventing the function from returning a valid value. I've added . . . BBCode tags to your post, please use them when posting code. Quote Link to comment Share on other sites More sharing options...
auspackuk Posted January 23, 2011 Author Share Posted January 23, 2011 Thanks for your response to my previous question. Your points on the open spaces in the between the equal sign and the value has been noted. However, i would want to say that the work "mess" could make someone who is new to this forum give up easily. How should the whole program look like to display the information needed? Should i separate the markup from the php script? Any tailed response will be appreciated from anybody. Regards. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 There's no need to have it in separate files, but you should handle all of the processing before starting any output whenever possible. So: pseudo-code flowchart-ish diagram if( form submitted ) { process form store the errors in an array if( errors array not empty ) { list errors to allow corrections to be made redisplay form } else { if no errors, do database insert, redirect, display success message, etc. } } else { display empty form. } Quote Link to comment Share on other sites More sharing options...
auspackuk Posted January 27, 2011 Author Share Posted January 27, 2011 THANK YOU FOR YOUR RESPONSE.hOWEVER, I HAVE APPLIED YOUR PROCEDURE BUT COULD NOT GET ANYTHING DISPLAYED FROM THE FORM. HOW FO YOU ADVISE THE WHOLE CODE SHOULD LOOK LIKE PLEASE? YOUR RESPONSE WILL BE APPRECIATED. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 Post your current code, along with any error it generates. 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.