Jump to content


Photo

how to redirect after inserting form into database


  • Please log in to reply
3 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 21 July 2006 - 05:41 PM

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
<?php
include_once("../includes/connection.php");
$title=$_POST['title'];
$content=$_POST['content'];

mysql_connect($host,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");

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

mysql_close();

header ('location:http://www.mysite.com/index.php?page=confirm');
?>
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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 21 July 2006 - 05:45 PM

you might try

header("LOCATION: index.php?page=confirm");

For security reasons, you might consider looking into adding addslashes() or strip_tags() to $title and $content.
Make a donation to phpfreaks. They need your help![br][br]

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 21 July 2006 - 05:48 PM

first of all you should read the sticky on headers

but here is how your header should look.

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


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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 johnwhello

johnwhello
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 16 October 2006 - 03:14 AM

header doesn't work at all in my .php files. It just won't redirect, even when using an empty-like .php file:

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

<body>
<?php
header("Location: http://www.google.com");
?>

</body>
</html>
How come my 'header' just won't redirect?

I tried:
- http://nl2.php.net/m...tion.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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users