Jump to content


This topic is now archived and is closed to further replies.


how to redirect after inserting form into database

Recommended Posts

I am having trouble redirecting to another page after form information has been entered into a database

Here is the code that I use to insert into the database

@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO news VALUES ('','$title','$content','')";


header ('location:http://www.mysite.com/index.php?page=confirm');
?>[/code]There is no html or head just what you see in the code.

I am trying to open a confirmation page telling the user that the data has been stored after they click the submit button

Share this post

Link to post
Share on other sites
you might try

[code]header("LOCATION: index.php?page=confirm");[/code]

For security reasons, you might consider looking into adding addslashes() or strip_tags() to $title and $content.

Share this post

Link to post
Share on other sites
first of all you should read the sticky on headers

but here is how your header should look.

[code=php:0]header('Location: http://www.mysite.com/index.php?page=confirm');[/code]

You want to make sure that there is no white space after the ?> in your connection.php or you will get the error [b]Cannot modify headers blablabla[/b]

Share this post

Link to post
Share on other sites
header doesn't work at all in my .php files. It just won't redirect, even when using an empty-like .php file:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mail form</title>

header("Location: http://www.google.com");

How come my 'header' just won't redirect?

I tried:
- http://nl2.php.net/manual/en/function.header.php
location starts with capital letter
- http://www.google.com/
- google.com
- www.google.com
- single and double quotes
- right in the end/ begin of <body> tag

So maybe something in the php.ini/ httpd.conf to be set?

Share this post

Link to post
Share on other sites


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.