md7dani Posted November 23, 2009 Share Posted November 23, 2009 I'm stuck with this simple problem. I need to insert data in Mysql and then hit submit and move to another page. My first thougt was to use Post but that didn't work. How do I use Get and Post to do what I want? Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/ Share on other sites More sharing options...
mraza Posted November 23, 2009 Share Posted November 23, 2009 if only you wants to move to next page after hitting submit you can use headers like: if(isset($_POST['submit'])) { //process datbase and use some statement if all goes well move to next page, // and if you need those variables in your next page you can use sessions header('Location: nextpage.php') } Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-963971 Share on other sites More sharing options...
md7dani Posted November 23, 2009 Author Share Posted November 23, 2009 I'm using a session on the same page so I can't use header, too bad.. Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964073 Share on other sites More sharing options...
mrMarcus Posted November 23, 2009 Share Posted November 23, 2009 I'm using a session on the same page so I can't use header, too bad.. ?? you can use sessions and header() on the same page. where'd you get that piece of information from? Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964095 Share on other sites More sharing options...
md7dani Posted November 23, 2009 Author Share Posted November 23, 2009 I'm using a session on the same page so I can't use header, too bad.. ?? you can use sessions and header() on the same page. where'd you get that piece of information from? I allways get this when I do that: Warning: Cannot modify header information - headers already sent by (output started at /mail_send.php:10) in /mail_send.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964175 Share on other sites More sharing options...
peterg0123 Posted November 23, 2009 Share Posted November 23, 2009 Hi, For the below code. Make sure that there is no code before header("Location: nextpage.php") that outputs any text or errors. Also try putting the code above all html code on the page, basically the first lines on the page above the HEAD, TITLE, BODY DOCTYPE... Also are you sure your mail_send.php is not outputting a message or error. That would stop the header location from working potentially? if(isset($_POST['submit'])) { // PROCESS DATA POST TO DB e.g. execute function here... if(!mysql_error()) { header('Location: nextpage.php'); } } else { //do the funky chicken } Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964263 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2009 Share Posted November 23, 2009 I allways get this when I do that: Warning: Cannot modify header information - headers already sent by (output started at /mail_send.php:10) in /mail_send.php on line 38 That error has nothing to do with sessions and a header() on the same page. It has to do with your code sending output before doing something that requires the use of a header - output started at /mail_send.php:10 (line 10) Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964265 Share on other sites More sharing options...
greatstar00 Posted November 23, 2009 Share Posted November 23, 2009 so, just remove any echo, print_r, var_dump, print, flush() etc, all these code before line header() Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964270 Share on other sites More sharing options...
Cardale Posted November 23, 2009 Share Posted November 23, 2009 ob_start will eliminate that. Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964275 Share on other sites More sharing options...
mraza Posted November 23, 2009 Share Posted November 23, 2009 add on top of your page as Cardale suggested and also at the bottom of your poge ob_end_flush so you will not get that error. <? ob_start (); // Start HTML tags etc All of your content ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182645-insert-data-in-mysql-and-move-to-another-page/#findComment-964380 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.