Ok I'm a beginner to Php and I have been given an assignment to do. I have completed it but I can't figure out how to get it to validate my data. I have put in a code that I thought would work and for some reason it doesn't. My assignment is this: "Write a code to convert the height entered by the user in foot and inches to centimeters. Handle the exceptions when negative values or decimal, non-numeric values are given as input.
So I created two php pages. One for the user to input their data, and the other to transfer the data and show the results. I'm stumped on validating the data start for hours now and it's about to drive me crazy. Here is what I got for my code. The first one is for the user and the other for transfer:
<html>
<head>
</head>
<body>
<form action="me3.php" method="get">
Please enter your height:<p>
Feet:<br>
<input type="text" name="feet"><p>
Inches:<br>
<input type="text" name="inches"><p><input type="submit" name="submit" value="Submit">
</form></body>
</html>
Here is my other:
<html>
<body><?php
$feet = $GET['feet'];
$inches = $GET['inches'];
$centi;
$meters;if (is_float($feet) && is_float($inches)) {
echo "You must enter a number bigger than 0. Please try again.";
}
else {// Calculates extra inches to feet if nessessary.
if ($inches > 12)
{
$inches = $inches%12;
$feet2 = $inches/12;
$feet = $feet + $feet2;
}// Calculates feet to meters.
$meters = $feet 0.3048;
$centi = $inches 2.54;echo "Your height is: " . $meters . " and " . $centi;
}
?></body>
</html>
Note here is the code I was trying to use to validate my data:
if (is_float($feet) && is_float($inches)) {
echo "You must enter a number bigger than 0. Please try again.";
}
else
// Put the rest of the code here because it passed the if statement{