prawn_86 Posted January 6, 2009 Share Posted January 6, 2009 Hi all, I want to redirect my users to a new page after the press submit on my form. I tried using the header() function but it didnt seem to work, its possible i was doing it wrong though. Im thinking i just need to put a simple line in the following peice of code, please tell me if im on the right track or not: //process any requests they have sent if (isset($_GET['submit']) && $_GET['submit'] == true){ $title = mysql_real_escape_string($_POST['title']); $url = mysql_real_escape_string($_POST['url']); $sql = "INSERT INTO `test_table` VALUES('', '$title', '$url');"; mysql_query($sql); } Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/ Share on other sites More sharing options...
Potatis Posted January 6, 2009 Share Posted January 6, 2009 Does this work? //process any requests they have sent if (isset($_GET['submit']) && $_GET['submit'] == true){ $title = mysql_real_escape_string($_POST['title']); $url = mysql_real_escape_string($_POST['url']); $sql = "INSERT INTO `test_table` VALUES('', '$title', '$url');"; mysql_query($sql); header("location: index.php"); exit; } Also.. Why is the first value in test_table empty? Is that for an id? Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730767 Share on other sites More sharing options...
prawn_86 Posted January 6, 2009 Author Share Posted January 6, 2009 Didnt work, kept giving an error, but i will keep trying with a few different styles of what you have suggested. And yes the first is blank for an ID Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730773 Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 what is the error you get? Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730779 Share on other sites More sharing options...
Potatis Posted January 6, 2009 Share Posted January 6, 2009 You should try to use NULL for id, without quotes. See if that helps. The redirect should work, I use it all the time. Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730780 Share on other sites More sharing options...
ukphoto Posted January 6, 2009 Share Posted January 6, 2009 I think a subtle change to; header ( 'Location: /index.php'); will actually work Mike Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730781 Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 The code given by Potatis is fine, and will work with no errors, I think the problem is somewhere else, prawn_86 can you post your error? Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730785 Share on other sites More sharing options...
premiso Posted January 6, 2009 Share Posted January 6, 2009 Does this work? //process any requests they have sent if (isset($_GET['submit']) && $_GET['submit'] == true){ $title = mysql_real_escape_string($_POST['title']); $url = mysql_real_escape_string($_POST['url']); $sql = "INSERT INTO `test_table` VALUES('', '$title', '$url');"; mysql_query($sql); header("location: index.php"); exit; } Also.. Why is the first value in test_table empty? Is that for an id? Either null or '' or actually defining the columns and omitting the id will work. It is just personal preference. Didnt work, kept giving an error, but i will keep trying with a few different styles of what you have suggested. And yes the first is blank for an ID And come on now, be more descriptive then "kept giving me an error". If you wonder why this is still unsolved, that is why, vagueness. What error did it give you? Where did it give the error? And how is it not working? Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-730858 Share on other sites More sharing options...
Potatis Posted January 6, 2009 Share Posted January 6, 2009 Either null or '' or actually defining the columns and omitting the id will work. It is just personal preference. Thanks for that, I was unsure, but now I know. Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-731133 Share on other sites More sharing options...
prawn_86 Posted January 6, 2009 Author Share Posted January 6, 2009 Hi all, sorry for not posting the error message last night, i was in a rush. Im at work now so cant access it, but it was something along the lines of that it was already accessing the page, the error was on the header() line. I think i actually need to change the submit part of my form also, so i will do that tonight and if i still cant get it working report back. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/#findComment-731151 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.