Jump to content

Recommended Posts

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);
}

Link to comment
https://forums.phpfreaks.com/topic/139673-redirect-to-different-page-after-submit/
Share on other sites

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?

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?

 

 

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.