zimmo Posted April 12, 2010 Share Posted April 12, 2010 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"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/ Share on other sites More sharing options...
the182guy Posted April 12, 2010 Share Posted April 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040495 Share on other sites More sharing options...
zimmo Posted April 12, 2010 Author Share Posted April 12, 2010 Nothing in the top before that, no spaces. The code given is all the error checking etc... then move onto check username exist and then insert. Cant see where its being sent? Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040502 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2010 Share Posted April 12, 2010 Read the error message (please). It tells you where the output is occurring at. Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040503 Share on other sites More sharing options...
zimmo Posted April 12, 2010 Author Share Posted April 12, 2010 Sorry here is the error: Warning: Cannot modify header information - headers already sent by (output started at /httpdocs/development/admin/test/sign_up.php:2) in /development/admin/test/sign_up.php on line 54 Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040521 Share on other sites More sharing options...
the182guy Posted April 12, 2010 Share Posted April 12, 2010 What's in the connect include? Looks like that's where the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040579 Share on other sites More sharing options...
dreamwest Posted April 12, 2010 Share Posted April 12, 2010 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 ); Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040582 Share on other sites More sharing options...
Mchl Posted April 12, 2010 Share Posted April 12, 2010 Cause it's better to use a trick than actually fix the error. Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040583 Share on other sites More sharing options...
harristweed Posted April 13, 2010 Share Posted April 13, 2010 I have found that omitting the closing php tag on the include file sometimes cures this problem Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040721 Share on other sites More sharing options...
Mchl Posted April 13, 2010 Share Posted April 13, 2010 I have found that omitting the closing php tag on the include file sometimes cures this problem That would be because you probably had a newline character (or other whitespace) after it. Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040751 Share on other sites More sharing options...
the182guy Posted April 13, 2010 Share Posted April 13, 2010 Need to look for whitespace or any outputting in the connect include. Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040761 Share on other sites More sharing options...
zimmo Posted April 13, 2010 Author Share Posted April 13, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040793 Share on other sites More sharing options...
zimmo Posted April 13, 2010 Author Share Posted April 13, 2010 Fixed it, needed to put my error code into relevant places. Thanks people Quote Link to comment https://forums.phpfreaks.com/topic/198303-headers-getting-sent-not-sure-how-to-fix/#findComment-1040819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.