Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Else statement keeps firing - simple registration form

    Hey
    Im pretty new to php have many to wade through a bun of syntax errors and code what is pretty much a completed registration form but its not quite there.

    The Plan:
    when the page loads the php checks to see if all the values are needed to register are there if not it creates a form to input the data. When the user hits submit the php runs again sees the datas there then sends to database.

    The Problem:
    The form is not displaying the php keeps creating blank records in to the table.

    PHP Code:
    <?php     $self $_SERVER['PHP_SELF'];
            
    $UserName $_POST['UserName'];
            
    $Password $_POST['Password'];
            
    $Email $_POST['Email'];
            
    if( ( !
    UserName ) or ( !Password) or ( !Email) )

    {

        
    $form ="To register fill in the details below and hit submit!";
        
    $form.="<form action=\"$self\" ";
        
    $form.=" method=\"post\"> Username: ";
        
        
    $form.="<input type=\"text\" name=\"UserName\"";
        
    $form.=" value=\"$UserName\">  <br>Password: ";
        
        
    $form.="<input type=\"text\" name=\"Password\"";
        
    $form.=" value=\"$Password\">  <br>Email: ";
        
        
    $form.="<input type=\"text\" name=\"Email\"";
        
    $form.=" value=\"$Password\">  <br>";
        
        
    $form.="<input type=\"submit\" value=\"Submit\">";
        
    $form.="</form>";
        echo( 
    $form );
    }    
    else
    $conn = @mysql_connect"localhost""root""")
        or die (
    "could not connect to mysql");  #Connect to mysql
        
    $db = @mysql_select_db"thewu"$conn )
        or die (
    "Could not select database"); #select database
        
        
    $sql "insert into logins
        (UserName,Password,Email) values
        (\"$UserName\",\"$Password\",\"Email\") "
    #Create Query
        
    $result= @mysql_query($sql$conn )
        or die(
    "Couldnt run query mate"); #Run query
        
    if( $result ) {echo( "New user $UserName added"); }
        }

              
    ?>
    Heres the code theres no error messages from php it seems to me too keep firing the else statement no matter what. Any help would be great
    thanks

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Sure you don't get any errors? No $ infront of the variables.
    Should also try this
    PHP Code:
    if((empty($UserName)) or (empty($Password)) or (empty($Email) ) 

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Thanks alot
    changing to your if statmenet everything worked perfect


  •  

    Posting Permissions

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