asdwal
asdwal

Reputation: 41

Redirect to another page after PHP script

I want to redirect to a confirmation page after the person has registered, once they have entered the details they need it is sent to the database using the PHP script below which all works. Although when I try to add a redirect using header, it does not run the PHP script. Any ideas to what I am doing wrong?

PHP

if (isset($_POST['firstname'], $_POST['surname'], $_POST['email'], $_POST['username'], $_POST['password'], $_POST['interest'])){

$firstname = ($_POST['firstname']);
$surname = ($_POST['surname']);
$username = ($_POST['username']);
$password1 = ($_POST['password']);
$email = ($_POST['email']);
$interest = ($_POST['interest']);

$result = mysql_query("INSERT INTO user (firstname,surname,username,password,email,interestarea,user_type) VALUES ('$firstname','$surname','$username','$password1','$email','$interest','normal')");
}

Upvotes: 0

Views: 644

Answers (4)

Krish R
Krish R

Reputation: 22711

You can add header('Location:yourpage.php');

 $result = mysql_query("INSERT INTO user (firstname,surname,username,password,email,interestarea,user_type) VALUES ('$firstname','$surname','$username','$password1','$email','$interest','normal')");
 header('Location:yourpage.php');
 exit();

You can add the @ob_start(); on top of the page.

Upvotes: 1

user849001
user849001

Reputation:

You should use MySQLi or PDO with prepared statements as mysql_ functions have been deprecated. You should at least look into using something like mysql_real_escape_string as you may be open to sql injection attacks.

Otherwise, like others have said use:

header("Location: new_page.php");
exit();

Upvotes: 2

zozo
zozo

Reputation: 8582

This is an educated guess on what your problem might be:

You say the page is redirecting, but the php is not parsed. So... if the page just displays your php, it means is outside php reading directory... check that pls (see if it starts with localhost/your ip/domain, etc).

Upvotes: 0

Ana Claudia
Ana Claudia

Reputation: 507

$result = mysql_query("INSERT INTO user (firstname,surname,username,password,email,interestarea,user_type) VALUES ('$firstname','$surname','$username','$password1','$email','$interest','normal')");

header('Location: page.php');

Include at the beginning of the script:

<?php 

ob_start();

?>

Upvotes: 1

Related Questions