Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ob_start();
- if (isset($_POST['send']) && $_POST['send']=='Send') {
- /* save_form_data_to_database(); if(some_error) {echo 'There was an error!';} else */
- { header('Location: '.$_SERVER['PHP_SELF'].'?status=ok'); exit; }
- }
- $str = ob_get_contents(); // get all printed text
- ob_end_clean();
- ?><!DOCTYPE html>
- <html>
- <head>
- <title>test for http://stackoverflow.com/questions/17028567/php-self-and-redirect-in-same-page</title>
- <style type="text/css">
- </style>
- <script type="text/javascript">
- </script>
- </head>
- <body>
- <form name="myform" action="" method="post">
- <input type="text" name="data1" value="aaa" />
- <input type="submit" name="send" value="Send" />
- </form>
- <?php
- var_export($_POST);
- var_export($_GET);
- echo '<p> error message: '.$str.'</p>';
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement