I'm Jad and I'm trying to make a math rounder. The problem is that when I click Do Math!, the echo doesn't work. Here's my code:
<?php
if(isset($_GET['math']))
switch ($_GET['math']) {
case "round":
if (isset($_POST['submit'])){
echo round($_POST['numb1']);
} else{
?>
<h1>Math Rounding!</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr>
<td>Number:</td>
<td>
<input type="text" name="numb1" placeholder="Number 1..." maxlength="44444444444444444444444444444444444444444444444444444444444444444444">
</td>
</tr>
<tr>
<th colspan=2>
<input type="submit" name="submit" value="Do Math!" style="height: 25px; width: 100px">
</th>
</tr>
</table>
</form>
</center>
<?php
break;
}
}
?>
So in each form change the value of hidden field(<input type="hidden" name="math" value="round">
) acoordingly.and also need to change the forms action to a single page.
<?php
if(isset($_POST['math']))
{
switch ($_POST['math'])
{
case "round":
echo round($_POST['numb1']);
exit;
case "round1":
echo round($_POST['numb1']);
exit;
}
}
else{
?>
<h1>Math Rounding!</h1>
<form action="<?php
echo $_SERVER['PHP_SELF'];
?>" method="post">
<input type="hidden" name="math" value="round">
<table border="0">
<tr><td>Number:</td><td>
<input type="text" name="numb1" placeholder="Number 1..." maxlength="44444444444444444444444444444444444444444444444444444444444444444444">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit"
value="Do Math!" style="height: 25px; width: 100px"></th></tr></table>
</form>
</center>
<?php
}?>
You need to set method to "get" and set form action to "" instead of .There is no need for it.
Your program should work now :) edit: set
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
to
<form action="" method="get">