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

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

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.

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

}

?>

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;

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.

Archived

This topic is now archived and is closed to further replies.

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