Retaining values across POST in a VERY basic php form

Karim1504

New Member
I'm going through a very basic php tutorial and am creating a calculator so I can get the hang of $_GET, $_POST and some general syntax.I created a very basic php function \[code\]calc();\[/code\] in a php file called functionadvanced.php. All it does is take 2 numbers, an operator, does the math and spits out the results (like I said, very basic tutorial). The funtion works so I won't post the code.I have another php file called calc.php that has my form for my calculator. Here's the code:\[code\]<?phpinclude "functionadvanced.php";$number1 = $_POST['num1'];$number2 = $_POST['num2'];$operator = $_POST['op'];?><html><body> <form action='calc.php' method='POST'> <input type='textbox' name='num1' value="http://stackoverflow.com/questions/3639679/<?php echo $_GET['$number1']; ?>"/> &nbsp; <select name="op" selected="<?php echo $_GET['$operator']; ?>"> <option value="http://stackoverflow.com/questions/3639679/+">+</option> <option value="http://stackoverflow.com/questions/3639679/-">-</option> <option value="http://stackoverflow.com/questions/3639679/*">*</option> <option value="http://stackoverflow.com/">/</option> </select> &nbsp; <input type='textbox' name='num2' value="http://stackoverflow.com/questions/3639679/<?php echo $_GET['$number2']; ?>"/> <input type='submit' valuehttp://stackoverflow.com/questions/3639679/='=' /> <input type='text' name='result' value="http://stackoverflow.com/questions/3639679/<?php echo calc($number1,$number2,$operator); ?>" /> </form></body></html>\[/code\]The form actually works, and shows the correct value that the calc function spits out, but when the page posts back it doesn't keep the posted back values in the fields. I thought I was suppose to use a $_GET to grab the values posted in the $_POST?
 
Back
Top