Jump to content

Recommended Posts

Can someone just help me with this code, the headers are already being sent from the form, not sure how to fix them here is the code;

 

<?php
// Include the connections script to make a database connection.
include("../inc/connect.php");

// Start the session to make sure no duplicates. Do later
//	session_start();
//	$_SESSION['session_name'] = '$sid';

// The form should post to itself.
if ( $_POST['submit'] ) {
$venue_name = $_POST['venue_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

if ( empty($venue_name) ) {
	$error['venue_name_error'] = '<div class="formerror">Please Enter your Fishery Venue Name.</div>';
}
if ( empty($username) ) {
	$error['username_error'] = '<div class="formerror">Please enter a username</div>';
}
if ( empty($password) ) {
	$error['password_error'] = '<div class="formerror">Please enter a password</div>';
}
if ( empty($email) ) {
	$error['email_error'] = '<div class="formerror">Please enter your email</div>';
}

// End of error checking, all fields covered.

if (!$error) {
	$sql = "SELECT * FROM fishery_a_signup WHERE username = '$_POST[username]' "; 
	$sql_result = mysql_query($sql); 

	if (mysql_num_rows($sql_result) !=0)
	{
			$error['username_taken'] = '<div class="formerror">The username is taken please choose another.</div>';
	}
else {
	# setup SQL statement
	$SQL = " INSERT INTO fishery_a_signup ";
	$SQL = $SQL . " (venue_name, username, password, email) VALUES ";
	$SQL = $SQL . " ('$venue_name', '$username', '$password', '$email') ";

	#execute SQL statement
	$result = mysql_db_query( *****,"$SQL",$connection );

	# check for error
	if (!$result) { 
	 echo("ERROR: " . mysql_error() . "\n$SQL\n");	 
	} else {
	$id = mysql_insert_id();
	header("Location: http://www.*****.com/development/login.html?id=$id");
	}
}
}
?>

Is there any whitespace before the open php tag <?php if there is then that will cause the headers already sent error because the whitespace will be treated as output and sent to the browser.

 

Are there any notices or other errors on the page? If so, these can be the causes of the headers already sent error.

 

Also, is there any echo/print or outputting in the connect include?

change

 

header("Location: http://www.*****.com/development/login.html?id=$id");

 

to

 

if (! headers_sent( ) ){

header( "Location: http://www.*****.com/development/login.html?id=$id" );
exit( 0 );
}
echo "<script language=Javascript>document.location.href='http://www.*****.com/development/login.html?id=$id';</script>";
exit( 0 );

Thanks again, found it in the connect, was not obvious though, its not throwing any error now. The only thing its not processing either, have I got the statements correct?

 

I need to error check as you can see for empty fields then check the username and then insert?

 

Its just staying on the same page when I fill in and submit?

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.