Jump to content

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


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;
}
}
?>

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.