I have created a small web site with a registration page.I want to get after the user fill the registration form and click the submit button , the page must be redirected to the login page.That redirection part is not working.Here is my database connection code to add data to my database and header function to redirect to login page. But when I test this in localhost, white blank page is shown as redirected page.Is there any error in this code.Data is successfully added to the database.That part is OK.If I put an echo statement right after the header() , that will be shown but not redirect to Login_page.I typed the header() as this also(header("Location:http//Login_page.html")).But the same problem arise.Please help me.Thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php 
  $con = mysql_connect("localhost","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("Real Truth", $con);

$sql="INSERT INTO register
VALUES
('$_POST[First_Name]','$_POST[Last_Name]','$_POST[E_Mail]','$_POST[Phone_No]','$_POST[Address]','$_POST[Career]','$_POST[username]','$_POST[password]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
 else{
     **header("Location:Login_page.html");**
  }
mysql_close($con);
?>

</body>
</html>

Recommended Answers

All 3 Replies

If you get a white page then the chances are it is getting stuck midway through the code, add this to the top of your PHP and see if it reads anything out:

ini_set('display_errors',1);

Equally, why do you have a double set of asterix's around your redirect?

It looks like your problem is here:

**header("Location:Login_page.html");**

remove the astrix's .. Also, don't use mysql_* functions. Your query is also unsafe.

Member Avatar for diafol

die() will prevent header() if it's called. Ideally header() should have an exit; after it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.