Jump to content

Recommended Posts

Hi!

 

I sell a custom product and the price is determine by the internal surface area of a rectangular mold. I would like to make a form in conjunction with PHP so that people can enter their mold's length, width and height and get a value for the internal surface area, and therefore know what product to buy. This is what I have so far:

 

The HTML form, calculate_form.html:

 

<form method="post" action="calculate.php">
  <p>Internal Length of Mould: <input name="l"
size="10" type="text"></p>
  <p>Internal Width of Mould: <input name="w" size="10"
type="text"></p>
  <p>Internal Height of Mould: <input name="h"
size="10" type="text"></p>
  <p><input name="submit" value="Calculate"
type="submit"></p>

 

 

AND the PHP script, calculate.php:

 

<?php
if (($_POST[l] == "") || ($_POST[w] == "") || ($_POST[h] =="")) {
  header("Location: calculate_form.html");
  exit;
}
$result = (($_POST[l]*(($_POST[h]*2)+$_POST[w])+(2*($_POST[w]*$_POST[h])))
}
echo "<title>Calculation Result</title>";
echo "<p>The result of the calculation is: $result</p>";
echo "<p><a href=\"calculate_form.html\" target=\"_self\">Do Another</a></p>";
?>

 

I greatly appreciate your help with modifying this puppy to work (in advance) :) :) :)

-Kas

 

 

Link to comment
https://forums.phpfreaks.com/topic/151718-need-some-help-with-equation-in-php/
Share on other sites

A rectangular cuboid has three pairs of identical faces: height*length, depth*height, depth*length. This means the surface area is given by 2hl+2dh+2dl.

 

Put into PHP this gives you:

 

$surfaceArea = 2*$_POST['h']*$_POST['l']+2*$_POST['d']*$_POST['h']+2*$_POST['d']*$_POST['l'];

 

You can add parentheses if you think it makes it more readable, but its sort of redundant because because multiplication takes higher precedence than addition.

 

It would be better if you named the sides like that. It's sort of ambiguous which side if which if you have something called "width" and "length". You normally say that you have the two dimensions "width" and "height", and then you can add the third dimension "depth".

Thanks for you help!

 

I probably should have been more specific. The SA is without the top side, but your equation is much simipler than the one I had before so I will definately use SA= 2lh+2wh+wl. My web page includes a diagram of what defines length, with, and height - this is the page I want to make a calc form for (http://www.tortugasoaps.com.au/customliners.html).

 

I put in the new equation organisation but I still can't get the form+PHP to work. I have never worked in PHP before, so I just did a lot of reasearch and put together the best approximation of what I thought could work, but there must be something missing becuase it doesn't work.

 

Here is a link to the test pages that I have been working on.

 

The form: http://www.ccaretta.com/tortuga/calculate_form.html

 

after submitting the values, it then goes to the PHP form and it is blank......

 

I just can't find any similar code to model it after (I've searched here and on the net).

 

CHEER!  ;D

 

 

I think I got it to work! (but still some minor errors)

 

FORM:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><input>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Calc</title>

</head>
<body>
<!---Calculator-->
<form method="post" action="calculate.php">
<br>
Internal Length of Mould(cm): <input name="length" size="10" type="text"
<br>
Internal Width of Mould(cm): <input name="width" size="10" type="text"
<br>
Internal Height of Mould(cm): <input name="height" size="10" type="text"
<br>
<INPUT TYPE=RESET NAME=RESET VALUE="Reset">
<input name="submit" value="Calculate" type="submit">
</form>
<!---endcalc--->

<br>
</body></html>

 

 

and the PHP code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><input>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Calc</title>
</head>
<body>

<?php

$length =$_POST['length'];
$height =$_POST['height'];
$width =$_POST['width'];

$surfacearea = 2*$length*$height+2*$width*$height+$width*$length;

// Print out the results:
print "<html><pre>";
print "The Length (cm): $length.\n)";
print "The Width (cm): $width.\n";
print "The Height (cm): $height.\n";
print "The total internal surface area of your mould (cm2)is: $surfacearea.\n";
print "</pre></html>\n";
?> 
<br>
</body></html>

 

I looked at some more PHP tutorials and whacked together some more simple ways of doing the PHP from how I first did it, and it seems to work now, except there is a form field that seems to hover at the top of the page but isn't in the code  ???

 

Also, do you know how I can combine the HTML form and PHP into one file/page? I am doing a bit of reading on it now.... humm..... hoping it is something simple and logical  :)

 

Thanks!

 

 

 

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.