SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error somewhere in here

    This causes me to get a blank screen. Can anybody find the syntax error? I think it's one of those things where I can't see it, but it's really obvious to everybody else. :P

    PHP Code:
    if(!$_POST) {
         
    The form was not filled out correctlyPlease go back and try again.<br />
     }
     
     if(
    ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$''$email') {
         echo 
    "Please enter a valid email address.<br />";
     }
     
     if(
    $password != $password2) {
         echo 
    "The two passwords you entered did not match. Please go back and try again.<br />"
     
    }
     
     if(
    strlen($password) < 6) {
         echo 
    "Invalid password length. Please go back and try again.<br />";
     }
     
     if(
    strlen($username) > 16) {
         echo 
    "Invalid username length. Please go back and try again.<br />";
     }
     
     
    $user_check mysql_query(SELECT FROM users WHERE username='$username');
     if(
    mysql_num_rows($user_check) > 0){
         echo 
    "That username is already registered. Please go back and try again.<br />";
     }
     
     
    $email_check mysql_query(SELECT FROM users WHERE email='$email');
     if(
    mysql_num_rows($email_check) > 0){
         echo 
    "That email address is already registered. Please go back and try again.<br />";
     } 


  2. #2
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol, you need an else saying they passes all the tests. A blank screen means nothing went wrong :P
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  3. #3
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Meh. Doesn't work. Even if there is an error, it doesn't echo anything out.

    Full script:

    PHP Code:
    <?php
       
    include('http://www.splitatoms.com/sa/includes/header.php');
       
    $link mysql_connect('localhost''my_username''my_password');
       if (!
    $link) {
          die(
    'Could not connect: mysql_error()');
       }
       
    mysql_select_db('mainframe');
       
       
    //create short variable names
       
    $email $_POST['email'];
       
    $username $_POST['username'];
       
    $password $_POST['passwd'];
       
    $password2 $_POST['passwd2'];  
       
       if(!
    $_POST) {
           
    The form was not filled out correctlyPlease go back and try again.<br />
       }
       
       if(
    ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$''$email') {
           echo 
    "Please enter a valid email address.<br />";
       }
       
       if(
    $password != $password2) {
           echo 
    "The two passwords you entered did not match. Please go back and try again.<br />"
       
    }
       
       if(
    strlen($password) < 6) {
           echo 
    "Invalid password length. Please go back and try again.<br />";
       }
       
       if(
    strlen($username) > 16) {
           echo 
    "Invalid username length. Please go back and try again.<br />";
       }
       
       
    $user_check mysql_query(SELECT FROM users WHERE username='$username');
       if(
    mysql_num_rows($user_check) > 0){
           echo 
    "That username is already registered. Please go back and try again.<br />";
       }
       
       
    $email_check mysql_query(SELECT FROM users WHERE email='$email');
       if(
    mysql_num_rows($email_check) > 0){
           echo 
    "That email address is already registered. Please go back and try again.<br />";
       }
       
       
    // Atempt Registration
       
    $password md5($password);
       
    $sql "INSERT INTO users (id, username, password, email) VALUES ('NULL', '$username','$password','$email')";
       
    $query mysql_query($sql) or die("Cannot query the database.<br>" mysql_error());
       echo 
    "You have been registered into our database.";
       
       include(
    'http://www.splitatoms.com/sa/includes/footer.php');
       
    ?>
    However, when I take out the clause from the first post, everything works fine. But they can submit invalid information.
    Last edited by chatmasta; Feb 26, 2005 at 12:04. Reason: I almost left the DB password and username in there. Lol


  4. #4
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
       if(!$_POST) {
           
    The form was not filled out correctlyPlease go back and try again.<br />
       } 
    Should be:

    PHP Code:
       if(!$_POST) {
           echo
    'The form was not filled out correctly. Please go back and try again.<br />';
       } 

  5. #5
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    die('Could not connect: mysql_error()'); 


    Should be:

    PHP Code:
    die('Could not connect: ' mysql_error()); 


    ...for correct output of the mysql error, if there is one.

    echo "The two passwords you entered did not match. Please go back and try again.<br />" should have a ; after it.

  6. #6
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is also something wrong with your regular expression, but I haven't been able to work out exactly what that is. (I'm not that good with them.)
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  7. #7
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you getting an ACTUAL Error message; if so give us the line.

    Also; unless I'm missing something, if they have errors, it will still add them into the database.

  8. #8
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not when I put in an else clause. (Which I just did)

    And no, I'm not getting an actual error message. If that was the case, this would be much easier.

    Still, it isn't working. I fixed what you guys said.

    Also, I'm pretty sure the regex works. It's out of a $50 book. :-p

    PHP Code:
    <?php
     
    include('http://www.splitatoms.com/sa/includes/header.php');
     
    $link mysql_connect('localhost''my_username''my_password');
     if (!
    $link) {
         die(
    'Could not connect: ' mysql_error()); 
     }
     
    mysql_select_db('mainframe');
     
     
    //create short variable names
     
    $email $_POST['email'];
     
    $username $_POST['username'];
     
    $password $_POST['passwd'];
     
    $password2 $_POST['passwd2'];  
     
     if(!
    $_POST) {
         echo 
    "The form was not filled out correctly. Please go back and try again.<br />";
     }
     
     if(
    ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$''$email') {
         echo 
    "Please enter a valid email address.<br />";
     }
     
     if(
    $password != $password2) {
         echo 
    "The two passwords you entered did not match. Please go back and try again.<br />";
     }
     
     if(
    strlen($password) < 6) {
         echo 
    "Invalid password length. Please go back and try again.<br />";
     }
     
     if(
    strlen($username) > 16) {
         echo 
    "Invalid username length. Please go back and try again.<br />";
     }
     
     
    $user_check mysql_query(SELECT FROM users WHERE username='$username');
     if(
    mysql_num_rows($user_check) > 0){
         echo 
    "That username is already registered. Please go back and try again.<br />";
     }
     
     
    $email_check mysql_query(SELECT FROM users WHERE email='$email');
     if(
    mysql_num_rows($email_check) > 0){
         echo 
    "That email address is already registered. Please go back and try again.<br />";
     }
     
     else {
     
     
    // Atempt Registration
     
    $password md5($password);
     
    $sql "INSERT INTO users (id, username, password, email) VALUES ('NULL', '$username','$password','$email')";
     
    $query mysql_query($sql) or die("Cannot query the database.<br>" mysql_error());
     echo 
    "You have been registered into our database.";
     
     }
     
     include(
    'http://www.splitatoms.com/sa/includes/footer.php');
     
    ?>


  9. #9
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Erm, I think your $50 book is wrong. When I put nothing but this into a script and run it:

    Code:
    <?php 
    
    if(ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', '$email') {
        echo "Please enter a valid email address.<br />";
    }
    else {
    	echo "Everything is ok!";
    }
    
    ?>
    I get a blank screen.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  10. #10
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Maine
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I'll look into that.

    But I've fixed everything else. The only problem is, an else statement still executed. So I was forced to put exit; into my conditional if. The problem there is that the footer never gets to load. Oh well.


  11. #11
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol, no one else noticed. Try changing all those ifs to else ifs, otherwise it checkes each individual thing, and the else only gets executed if the last if comes up false.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT


Bookmarks

Posting Permissions

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