Padgoi Posted August 28, 2007 Share Posted August 28, 2007 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. Link to comment https://forums.phpfreaks.com/topic/67147-little-help-with-calculating-a-few-numbers-via-a-form/ Share on other sites More sharing options...
Fadion Posted August 28, 2007 Share Posted August 28, 2007 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/67147-little-help-with-calculating-a-few-numbers-via-a-form/#findComment-336770 Share on other sites More sharing options...
Fadion Posted August 30, 2007 Share Posted August 30, 2007 Now that i saw it, i made a typo in the code. In the if and elseif parts i wrote $show instead of $shoe. Link to comment https://forums.phpfreaks.com/topic/67147-little-help-with-calculating-a-few-numbers-via-a-form/#findComment-337491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.