Jump to content

Little help with calculating a few numbers via a form...


Padgoi

Recommended Posts

Ok, so I am trying to put up a script where users enter certain info into a form and after they enter the info in, they click submit and the script makes a certain calculation using those numbers.  For instance, the form should look something like this:

 

Name:

Age:

Height in inches:

Weight in pounds:

Shoe size:

 

Then the script takes the 4 numbers inputted in the age, height, weight, and shoe size rows and does this calculation and shows the user the result:

 

(Height + Weight) * Age) / Shoe Size

 

Can anyone help me out with something like this?  I'd be very appreciative.  Thanks in advance.

 

This should do it:

 

<form name="myform" method="post" action="">
    <input name="name" type="text" />
    <input name="age" type="text" />
    <input name="height" type="text" />
    <input name="weight" type="text" />
    <input name="shoe" type="text" />
    <input type="submit" name="Submit" value="Submit" />
</form>

<?php
if(array_key_exists('name', $_POST)){
$name = $_POST['name'];
$age = $_POST['age'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$shoe = $_POST['shoe'];

if($age == "" or $height == "" or $weight == "" or $show == ""){
	echo "Please fill all the fields";
} elseif(!is_numeric($age) or !is_numeric($height) or !is_numeric($weight) or !is_numeric($show)){
	echo "Please input valid data";
} else{	
	$result = (($height + $weight) * $age) / $shoe;
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.