Jump to content

Php could not display my values on the page .Any idea on what is missing please?


auspackuk

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.