Jump to content

Redirection help


sudsy1970

Recommended Posts

Not sure if this is in the right forum as it's kind of php and MySQL.

 

I have created a form to update a table (eventually) and i want to direct the user to another page after a sucessful entry.

 

The code i used for this was:

// Inserts the data from the register page into the database

         $sql = "INSERT into user (firstname, surname, email, password, user)
             VALUES ('$Firstname', '$Surname', '$Email', '$Password1', '$User') ";
         mysql_query($sql);
           echo "info entered into database";
           header("Location:home.php");

 

However all  is not well as i get the following error

info entered into database

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Cosford\registerdetails.php:81) in C:\xampp\htdocs\Cosford\registerdetails.php on line 104

 

Any one have any ideas as to what this error message is and how to resolve it.

 

Cheers for looking

 

Full code posted below

<?php
session_start();

$Firstname = ($_POST['firstname']);
$Surname = ($_POST['surname']);
$Email = ($_POST['email']);
$Password1 = ($_POST['password']);
$Password2 =($_POST['password2']);
$User = ($_POST['user']);
$errors = array();


if (empty($Firstname))
{
   $errors[] = 'Please enter your Firstname';
}

if (empty($Surname))
{
   $errors[] = 'Please enter your Surname';
}

if (empty($User))
{
   $errors[] = 'You must select a Username';
}

if (empty($Email))
{
   $errors[] = 'Please enter an email address';
}

// Email verification amended from http://www.plus2net.com/php_tutorial/php_email_validation.php

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email))
{
   $errors[] = 'This is not a valid email address';
}

if (strlen($Password1) < 6)
{
   $errors[] = "Your password must be 6 characters";
}

if (empty($Password1))
{
   $errors[] = 'No Password';
}

if ($Password1 != $Password2)
{
   $errors[] = 'Your passwords do not match';
}


if (count($errors) == 0)
{
   // Connect to mysql

   $dbServer = mysql_connect("localhost", "web", "LzAUScXJ4tfAUvcm");
   mysql_select_db("cosfordfc", $dbServer);
}
else
 {
	echo 'The following errors were found:<ul>';
             foreach ($errors as $error)
              {
                echo "<li>$error</li><br>";
                echo '</ul>';
      }
                include ("registerform.php");
 }

if (!$dbServer)
{
echo "Failed to connect to MySQL";
exit;
}
    else
     {
       echo "connected to the database.<br>Your details have been entered<br>";
     }
   //Checks the database for existing records before writing.Username is primary key and must be unique.

   $sql = ("SELECT * from user WHERE user='$User'");
   $queryResult = mysql_query($sql);

if (mysql_num_rows($queryResult)!=0)
{
    echo "Please fill in the form again<br>";
    echo "Sorry the username you selected is already taken by another member<br>";
    include ("registerform.php");


}
      else
       {
         // Inserts the data from the register page into the database

         $sql = "INSERT into user (firstname, surname, email, password, user)
             VALUES ('$Firstname', '$Surname', '$Email', '$Password1', '$User') ";
         mysql_query($sql);
           echo "info entered into database";
           header("Location:home.php");
        }
        
// will show if there has been an error and tell what error it is
if (mysql_error()) 
{
             
  mysql_error();
  
}

     
    
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/205037-redirection-help/
Share on other sites

Archived

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

×
×
  • 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.