Jump to content

header problem


knobby2k

Recommended Posts

Hi guys,

 

I've got a header problem. I've read the header sticky post but i'm still not getting anywhere.

 

I am currently working on a registration form which loops though checking the data entered meets certain criteria by calling various functions (min length, max length, preg match, etc...), if anything returns 'false' then the form is reproduced with the error message of why it failed and what needs to be changed. If everything returned is 'true' then all day matches what is expected and the code then runs an 'insert' command. If the insert is successful then the code should forward the user to a new page displaying 'registration complete'.

 

However, the way I have written my code I am finding it near impossible to get the forward to be before anything is output to the browser therefore causing the header error. I have tried moving things around but i'm having no luck.

 

The error I am getting is:

 

Warning: Cannot modify header information - headers already sent by (output started at /websites/blahblahblah/register.php:6) in /websites/blahblahblah/register.php on line 77

 

The code there is relevant though as it is the code that make the connection to my DB.

 

<!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" />

<?php
// *** Connection - START ***
// connect to database
$connect = @mysql_connect("test", "test", "test") or die(mysql_error());
  
if (!$connect) 
{ 
        do_error("Could not connect to the server"); 
} 

@mysql_select_db("test_db",$connect)or do_error("Could not connect to the database");
// *** Connection - END ***

// This file includes all of the check functions for the code to run through
include("check.php"); 

if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
$data= new check($_POST);

$data->name('forename');
$data->name('surname');

if ( $data->pass == true )
{
	// Now we have the required data in the correct format do the code required to complete registration 

	$forename=$data->input['forename'];
	$surname=$data->input['surname'];

	$query="INSERT INTO users ( forename, surname ) VALUES ('$forename' , '$surname' )";

	if (mysql_query($query,$connect))
	{										
		//echo "success";

		// once data is inserted, go to complete page
		header ("location: complete.php");
		exit;
	}
	else
	{
		echo "Error: Please try again.";
	}
}
}
else
{
$data= new check();
}
?>

 

What am I actually doing wrong and how can i possibly get the insert script higher up the code??

 

Thanks

 

 

Link to comment
Share on other sites

Hi guys,

 

Thanks for your replies.

 

The code i've posted is only a snippet, the full file is about 300 lines of code and has a lot of other html so won't i need those first 4-5 lines??

 

Also the link that you sent me didn't work titan. Where would i start and end the ob_start/ob_flush?

 

Thanks again

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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