samoi Posted December 3, 2008 Share Posted December 3, 2008 <?php error_reporting(E_ALL & E_NOTICE); echo '<html dir="ltr"> <head> <title>Site</title> </head> <body bgcolor="#ECD9C6"> <table align="center" width="777" height="700"> <tr> <td background="bg_e.jpg"> <p> </p> <p> </p> <table height="40" width="777"> <tr> <th> <font face="Arial" size="5" color="#EDD5C3"> page3 </font></th> </tr> </table> <table height="630" width="777"> <tr> <td>'; if(!$_POST) { header('Location: insert.php') or die(); } else { require_once('config.php'); $insert = "INSERT INTO samoi (event, date) VALUES ('$event', '$date')"; $insertSQL = mysql_query($insert) or die(mysql_error()); echo 'The new event has been submitted <br> hit <a href="index.php"> this link </a> to view them'; } function clean($str) { return mysql_escape_string($str); } ?> it's not redirecting !! How can I get the error? Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/ Share on other sites More sharing options...
Maq Posted December 3, 2008 Share Posted December 3, 2008 1) You should be using if(!isset($_POST['your_name'])) Not: if(!$_POST) 2) To turn error reporting temporarily on put this at the top of your script. ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705120 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 If anything is echo'd to the screen the header function cannot work. I would suggest replacing this: header('Location: insert.php') or die(); with echo '<script>location.href = "insert.php"</script>'; Will give you the same result without having to re-do your current code. Although I would suggest outputting everything at the end by storing the output into a string, instead of just echo'ing it out. But yea. Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705124 Share on other sites More sharing options...
samoi Posted December 3, 2008 Author Share Posted December 3, 2008 1) You should be using if(!isset($_POST['your_name'])) Not: if(!$_POST) 2) To turn error reporting temporarily on put this at the top of your script. ini_set ("display_errors", "1"); error_reporting(E_ALL); Ok, I have two questions, 1 - I have the page insert.php and it has a form with a submit button under the name="submitBTN", is it the name that I put in this !isset($_POST['submitBTN']) if it is, then I have tried it and it didn't work ! 2 - I'm sorry, but I feel curies, this ini_set ("display_errors", "1"); is not the same as in the php.ini file? it's set to On already. Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705137 Share on other sites More sharing options...
samoi Posted December 3, 2008 Author Share Posted December 3, 2008 If anything is echo'd to the screen the header function cannot work. I would suggest replacing this: header('Location: insert.php') or die(); with echo '<script>location.href = "insert.php"</script>'; Will give you the same result without having to re-do your current code. Although I would suggest outputting everything at the end by storing the output into a string, instead of just echo'ing it out. But yea. Wow, very rich info. I will try it, and will come back ! Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705142 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 Ok, I have two questions, 1 - I have the page insert.php and it has a form with a submit button under the name="submitBTN", is it the name that I put in this !isset($_POST['submitBTN']) if it is, then I have tried it and it didn't work ! 2 - I'm sorry, but I feel curies, this ini_set ("display_errors", "1"); is not the same as in the php.ini file? it's set to On already. Thank you in advance 1. Yes it is the name you put in there. 2. The only error I would see is calling the header function after you have echo'd text to the screen. As I mentioned above that is not kosher. Also check that you are using "POST" variables and not "GET" in your form. As for the errors, if display_errors is set in the php.ini to on, yes that means it is on but this can be overwritten by .htaccess so it is good practice when debugging to add that to the top just in case. Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705145 Share on other sites More sharing options...
samoi Posted December 3, 2008 Author Share Posted December 3, 2008 If anything is echo'd to the screen the header function cannot work. I would suggest replacing this: header('Location: insert.php') or die(); echo '<script>location.href = "insert.php"</script>'; Will give you the same result without having to re-do your current code. Although I would suggest outputting everything at the end by storing the output into a string, instead of just echo'ing it out. But yea. Wow, very rich info. I will try it, and will come back ! It works ! Thank you. But do you think that it will be a good protection? since the redirecting is a java script? what if I have a firefox, and have the addon web devoloper toolbar, and I disabled the java script from the tool bar, I'll still get the same result I came with, right? Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705153 Share on other sites More sharing options...
samoi Posted December 3, 2008 Author Share Posted December 3, 2008 Ok, I have two questions, 1 - I have the page insert.php and it has a form with a submit button under the name="submitBTN", is it the name that I put in this !isset($_POST['submitBTN']) if it is, then I have tried it and it didn't work ! 2 - I'm sorry, but I feel curies, this ini_set ("display_errors", "1"); is not the same as in the php.ini file? it's set to On already. Thank you in advance 1. Yes it is the name you put in there. 2. The only error I would see is calling the header function after you have echo'd text to the screen. As I mentioned above that is not kosher. Also check that you are using "POST" variables and not "GET" in your form. As for the errors, if display_errors is set in the php.ini to on, yes that means it is on but this can be overwritten by .htaccess so it is good practice when debugging to add that to the top just in case. Yes it works as maq taught me Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705156 Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 If javascript is disabled that will not work, since it does use javascript. To use the header function you need to call that before anything is output to the screen, so do that if check at the top of the page and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705158 Share on other sites More sharing options...
samoi Posted December 3, 2008 Author Share Posted December 3, 2008 If javascript is disabled that will not work, since it does use javascript. To use the header function you need to call that before anything is output to the screen, so do that if check at the top of the page and it should work. wow man, you're very helpful and quick responder Thank you very much. I'll give it a shot and come back ! Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705159 Share on other sites More sharing options...
samoi Posted December 3, 2008 Author Share Posted December 3, 2008 If javascript is disabled that will not work, since it does use javascript. To use the header function you need to call that before anything is output to the screen, so do that if check at the top of the page and it should work. I really wish to be your friend Maaaaan You're professional. I appreciate it, it works just fine with your help. You know what makes me sad right now? that I have read php books and I still don't recall some information form what I have read ! But thank you Quote Link to comment https://forums.phpfreaks.com/topic/135374-solved-its-not-redirecting-if-_post-any-suggestions/#findComment-705168 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.