We help IT Professionals succeed at work.
Get Started

Member registration [Email won't connect to database]

PSTCAT
PSTCAT asked
on
352 Views
Last Modified: 2012-08-14
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
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE