dudejma Posted August 8, 2011 Share Posted August 8, 2011 I've been wondering this for some time, but when you submit a form, and you want it to go back to the same form and having it echo a variable such as "Record added!". How do you do that? Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/244166-echoing-a-variable/ Share on other sites More sharing options...
MasterACE14 Posted August 8, 2011 Share Posted August 8, 2011 set the form 'action' value to '' (empty). <?php if(isset($_POST['submit'])) { // if the form has been submitted... echo 'Record Added!'; // insert record into database etc here... } else { // if the form has not been submitted, display the form... ?> <form action='' method='post'> <input type='submit' name='submit' value='Add Record'> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244166-echoing-a-variable/#findComment-1253924 Share on other sites More sharing options...
dudejma Posted August 8, 2011 Author Share Posted August 8, 2011 What if you have an error verification part. So, you check if the form is submitted already, then do the error verification, then you check if $errors == "". Do you put it after the verification check or still after the submit button check? Because when I put it after either one it doesn't work and when I put the end curly bracket at the very end, it makes the screen white. Quote Link to comment https://forums.phpfreaks.com/topic/244166-echoing-a-variable/#findComment-1253930 Share on other sites More sharing options...
MasterACE14 Posted August 8, 2011 Share Posted August 8, 2011 you put it inside the... if(isset($_POST['submit'])) { Quote Link to comment https://forums.phpfreaks.com/topic/244166-echoing-a-variable/#findComment-1253938 Share on other sites More sharing options...
dudejma Posted August 8, 2011 Author Share Posted August 8, 2011 I put it there and then I put the end curly bracket after the form and it only shows the footer after the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/244166-echoing-a-variable/#findComment-1253943 Share on other sites More sharing options...
dudejma Posted August 8, 2011 Author Share Posted August 8, 2011 Ohhhh, I read what you were saying wrong! I got it now. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/244166-echoing-a-variable/#findComment-1253946 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.