Jump to content

Simple register script, PLEASE help, its not that simple!


nealec

Recommended Posts

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

Link to comment
Share on other sites

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.)

Link to comment
Share on other sites

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.";

}

?>

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.

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.