I am learning PHP and i got into stupid problem.
I am using LAMP server to run some of the little apps I create.
Recently I made a converter just for practice because it seems to quite easy. I got HTML part of it.
<html>
<head> </head>
<body>
<form method="post" action="test.php">
<h2> Convert length: </h2>
<p>
Select conversion direction:
<br>
<input type="radio" checked="checked" value="1" name="button">
Feet to meters
<br>
<input type="radio" value="2" name="button">
Meter to feet
<br>
</p>
<p>
Value to be converted:
<br>
<input type="text" name="cvalue">
</p>
<p>
<input type="submit"value="Convert">
</p>
</form>
</body>
</html>
Then I made this PHP file, test.php here is the code:
The code basicaly converts from feet to meter and back, at the same time it stores the each conversion in TXT file on server called conversions.txt.
<?php
if ($_POST['button']=="1")
{
$result=($_POST['cvalue']) / 3.2808399;
echo ($_POST['cvalue'])."Feet=".$result."Meters";
$fp = fopen ('conversions.txt', 'a');
fwrite($fp,"Your latest result =".$result."Meters,");
fclose($fp);
}
else
{
$result=($_POST['cvalue']) * 3.2808399;
echo ($_POST['cvalue'])."Meters=".$result."Feet";
$fp = fopen ('conversions.txt', 'a');
fwrite($fp,"Your latest result =".$result."Feet,");
fclose($fp);
}
//$fp = fopen ('conversions.txt', 'a');
//fwrite($fp,"Your latest result =".$result);
//fclose($fp);
?>
If you would run this code you will see that it works good and neat. The question is how to make first page, that you got from HTML code to stay the same after clicking Convert button which pushes it into PHP script. And Show the result right under into reapering box insted of next page.
I been googling the redirection, but all i got is header redirect which not working properly because i have server data comunication.
I might will find the hidden box tutorial, but i have no clue how to make page not to jump to /text.php and just give result to hidden box. Please help :)