troubleshooting Question

Member registration [Email won't connect to database]

Avatar of PSTCAT
PSTCATFlag for United Kingdom of Great Britain and Northern Ireland asked on
MySQL ServerPHP
3 Comments1 Solution356 ViewsLast Modified:
Basically, I have a registration form with 3 text fields. Username, Password and Email.

The username and password appear in my database when signing up but the email is refusing to.
I have two files, reg.php and regcheck.php.

Here is my code:

reg.php
<?php
require_once 'database.php';
?>
<body>
<form method="post" action="regcheck.php" name="register">
  <br>
<label for="username">Username: </label>
<br>
<input id="username" class="input_field" type="text" onmouseout="if(this.value==''){this.value='Username...';}" onclick="javascript:void(0);if(this.value=='Username...'){this.value='';}" maxlength="150" value="Username..." size="35" name="user">
<br>
<br>
<label for="password">Password: </label>
<br>
<input id="password" class="input_field" type="password" onmouseout="if(this.value==''){this.value='Password...';}" onclick="javascript:void(0);if(this.value=='Password...'){this.value='';}" maxlength="100" value="Password..." size="35" name="pass">
<br>
<br>
<label for="email">Email: </label>
<br>
<input id="email" class="input_field" type="email" onmouseout="if(this.value==''){this.value='Email...';}" onclick="javascript:void(0);if(this.value=='Email...'){this.value='';}" maxlength="100" value="Email..." size="35" name="email">
<br />
<br />
<input id="search_btn" type="submit" value="Continue" >
<b>I agree to the Terms &amp; Conditions.</b>
<br>
</form>

Open in new window


regcheck.php
<?php
if(
    isset( $_POST['user'] ) &&
    isset( $_POST['pass'] )
	isset( $_POST['email'] ))
{
    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( strlen( $_POST['email'] ) < 4 )
    {
        echo "Email must be valid.";
    }
    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'] );
		$email = ( $_POST['email'] );

        $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";

        
        if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )
        {
            $sqlRegUser =     "INSERT INTO
                        user( username, password, email )
                    VALUES(
                        '". $username ."',
                        '". $password ."',
						'". $email ."',
						 )";

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

Open in new window


Any help would be appreciated, I can't seem to find any errors. Maybe I'm missing something...
Thanks
ASKER CERTIFIED SOLUTION
Lukasz Chmielewski

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros