www.webdeveloper.com
Results 1 to 3 of 3

Thread: php registration code won't stop giving me the same error over and over

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    Exclamation php registration code won't stop giving me the same error over and over

    Here is the code please have a look at it for me and see if you can find my errors i am a newbie to coding first time actually making a registration code.
    i keep getting the same error over and over and won't submit to database also: This is the error:You must enter a valid email address to register.


    <?php
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    session_start();

    include("connect.php");

    if(isset($_POST['submit'])){

    //get all posted data
    $username = $_POST['user'];
    $password = $_POST['pass'];
    $confirmpassword = $_POST['confirmpassword'];
    $email = $_POST['email'];

    if($username && $password && $confirmpassword && $email)
    {
    if((strlen($username)<=6) || (strlen($password)<=6))
    {
    echo "The username or password is too short!";
    }
    else
    {
    if ($password === $confirmpassword)
    {
    $sql = mysql_query("SELECT * FROM users WHERE username='$username'");
    $numrows = mysql_num_rows($sql) or die(mysql_error());
    if ($numrows == 0)
    {
    echo "The username '$username' already exists!";
    }
    else
    {
    $md5password =md5($password);

    mysql_query("INSER INTO users (id, username, $md5password, email) VALUES
    ('','$username','$confirmpassword')");
    echo "Registration Successful! <a href='login.php'>Click here to login now!</a>";
    }
    }
    else
    {
    echo "Passwords do not match enter both fields!!";
    }
    }
    }
    else
    {
    die("Please enter all the required fields!!");
    }

    }

    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,248
    Here's your code wrapped in this forum's [php]...[/php] tags, which should make it a lot easier for us to help you:
    PHP Code:
    <?php
    ini_set
    ('display_errors',1); 
    error_reporting(E_ALL);
    session_start();

    include(
    "connect.php");

    if(isset(
    $_POST['submit'])){

    //get all posted data
    $username $_POST['user'];
    $password $_POST['pass'];
    $confirmpassword $_POST['confirmpassword'];
    $email $_POST['email'];

    if(
    $username && $password && $confirmpassword && $email)
    {
       if((
    strlen($username)<=6) || (strlen($password)<=6))
       {
       echo 
    "The username or password is too short!";
       }
       else
        {
    if (
    $password === $confirmpassword)
    {
        
    $sql mysql_query("SELECT * FROM users WHERE username='$username'");
         
    $numrows mysql_num_rows($sql) or die(mysql_error());
        if (
    $numrows == 0)
        {
           echo 
    "The username '$username' already exists!";
         }
        else
        {
        
    $md5password =md5($password);
        
           
    mysql_query("INSER INTO users (id, username, $md5password, email) VALUES 
           ('','
    $username','$confirmpassword')");
           echo 
    "Registration Successful! <a href='login.php'>Click here to login now!</a>";
        }
    }
    else
     {
        echo 
    "Passwords do not match enter both fields!!";
     }
    }
     }
    else
    {
    die(
    "Please enter all the required fields!!");
    }

     }

    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,248
    The error message you described, "You must enter a valid email address to register," is not anywhere in that PHP code. Could it be a JavaScript function on the form page itself?

    A different problem I did notice is this line:
    PHP Code:
           mysql_query("INSER INTO users (id, username, $md5password, email) VALUES
           ('','
    $username','$confirmpassword')"); 
    Problem #1 is that your probably want "password" instead of "$md5password" in the field list (the first set of parentheses, and the second problem is that you list 4 fields but only supply 3 values (looks like you left out the email address value).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles