nealec Posted January 27, 2011 Share Posted January 27, 2011 Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2011 Share Posted January 27, 2011 output started at ... .../regcheck.php:43 (line 43) Something at or up to line 43 in regcheck.php, probably the "You Are Registered And Can Now Login" is output that is being sent to the browser. You cannot send output before you send a html header(). You would need to determine what is sending that output and either eliminate it or rearrange the logic in the program so that you only send output if you are going to remain on the page (It doesn't make sense to send output to the browser if you are going to redirect to another page.) Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1165952 Share on other sites More sharing options...
nealec Posted January 27, 2011 Author Share Posted January 27, 2011 Hi thanks for the reply, i didnt write any of this code and i dont know what im doing at all, pls could i send u the code and you tell me what to do? Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1165953 Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2011 Share Posted January 27, 2011 could i send u the code I think you misunderstood what a public help forum is for. You post the code you are having a problem with and someone with an interest in helping with the problem will reply in the forum. Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1165955 Share on other sites More sharing options...
nealec Posted January 27, 2011 Author Share Posted January 27, 2011 Sorry, Here it is. <?php if( isset( $_POST['user'] ) && isset( $_POST['pass'] ) ) { if( strlen( $_POST['user'] ) < 4 ) { echo "Username Must Be More Than 4 Characters."; } elseif( strlen( $_POST['pass'] ) < 4 ) { echo "Passwrod Must Be More Than 4 Characters."; } elseif( $_POST['pass'] == $_POST['user'] ) { echo"Username And Password Can Not Be The Same."; } else { include( 'database.php' ); $username = mysql_real_escape_string( $_POST['user'] ); $password = md5( $_POST['pass'] ); $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'"; if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO user( username, password ) VALUES( '". $username ."', '". $password ."' )"; if( !mysql_query( $sqlRegUser ) ) { echo "You Could Not Register Because Of An Unexpected Error."; } else { echo "You Are Registered And Can Now Login"; $formUsername = $username; header ('location: Login.php'); } } else { echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One."; $formUsername = $username; } } } else { echo "You Could Not Be Registered Because Of Missing Data."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1165957 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 this is a problem. there is no point in echoing anything if you are going to redirect the user to another page. and if you echo anything, you can't use header() afterward // echo "You Are Registered And Can Now Login"; // Why? // $formUsername = $username; // Why? header ('location: Login.php'); exit; Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1166003 Share on other sites More sharing options...
nealec Posted January 27, 2011 Author Share Posted January 27, 2011 Thankyou for the reply, im probably goin to annoy you now by being so stupid, but am i supposed to paste the code you just left somewhere in my regcheck.php file? // echo "You Are Registered And Can Now Login"; // Why? // $formUsername = $username; // Why? header ('location: Login.php'); exit; I have no idea what im doing or what echos are. Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1166022 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 echo means "send data to browser". you can't "send data to browser" before using header(). so, if there is header() after an echo, // comment out those echos. or just replace your code with the modified version i provided. Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1166026 Share on other sites More sharing options...
nealec Posted January 27, 2011 Author Share Posted January 27, 2011 Oh, ok great thankyou Quote Link to comment https://forums.phpfreaks.com/topic/225846-simple-register-script-please-help-its-not-that-simple/#findComment-1166029 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.