I need help. It seems that the code has one error: it says that I have undefined index:number
, but I already declared a name for my textbox with the name number. I also wrote code that if $_POST['number'] == ''
, but it seems nothing has fixed this. Please help me.
<html>
<head>
<title>SUBMIT</title>
</head>
<body>
<form action="" method='post'>
<input type='text' name='number'><br><br>
<input type='submit' name='celsius' value='celsius'>
<input type='submit' name='fahrenheit' value='fahrenheit'>
</form>
<?php
function celsius($x){
$cel=($x -32) * 5/9;
return $cel;
}
function fahrenheit($x){
$far=$x * 9/5 + 32;
return $far;
}
if($_POST['number']== ""){
echo 'plese input a number';
}
else if($_POST['number'] != is_numeric($_POST['number'])){
echo 'type only numbers';
}
else if(isset($_POST['celsius'])){
$x=$_POST['number'];
if($_POST['celsius']){
echo $x.' Fahrenheit is '.celsius($x);
}
}else if(isset($_POST['fahrenheit'])){
$x=$_POST['number'];
if($_POST['fahrenheit']){
echo $x.' Fahrenheit is '.fahrenheit($x);
}
}
?>
</body>
</html>