steph90 Posted October 13, 2010 Share Posted October 13, 2010 I cannot figure out how to retain the inputted information once submit is pressed. I want the user to enter their first name, last name, hours of work, and hourly pay rate. Then, I want them to press submit. Their pay will be calculated and displayed, but I still want their inputted information to be visible. How can I do that?? Here is my code: <html> <head> <?php $pay = $_POST['pay']; $hours = $_POST['hours']; $extra = $_POST['extra']; $rate = $_POST['rate']; if ($hours > 40){ $extra=$hours-40; $hours=40; $pay=($extra*1.5*$rate)+($hours*$rate); } else { $pay=$hours*$rate; } echo "Your pay is: <br /> $ $pay <br />" ; ?> </head> <body> <form method='post' action='pay2.php'> First Name: <input type='text' name='first'><br/> Last Name: <input type='text' name='last'><br/> Hours of Work: <input type='text' name='hours'><br/> Hourly Pay Rate: <input type='text' name='rate'><br/> <input type='submit' value='submit'> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Oziam Posted October 13, 2010 Share Posted October 13, 2010 pass the value to the fields e.g add the variables required to your form fields like; <body> Hours of Work: <input type='text' name='hours' value="<?php echo $hours;?>"><br/> etc.... </body> Quote Link to comment Share on other sites More sharing options...
steph90 Posted October 13, 2010 Author Share Posted October 13, 2010 Thank you for the response, but that does not work. Is there something else that I should be adding in another part of the code? Quote Link to comment Share on other sites More sharing options...
rwwd Posted October 13, 2010 Share Posted October 13, 2010 <input type='text' name='first' value="<?php echo (isset($_POST['first']) ? $_POST['first'] : '');?>"> Repeat that logic for the rest of the elements, then hey-presto, data retention. Rw Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.