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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Registration code

    The code for posting registration info to the database dies and does not display an error.

    PHP Code:
    <?php 
    include_once("scripts/connect_to_mysql.php");
    $message ='';

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

        
    $username $_POST['username'];
        
    $fname $_POST['fname'];
        
    $lname $_POST['lname'];
        
    $email $_POST['email'];
        
    $pass1 $_POST['pass1'];
        
    $pass2 $_POST['pass2'];
        
        
    //error handling
        
    if((!$username)||(!$fname)||(!$lname)||(!$email)||(!$pass1)||(!$pass2)){
            
    $message='Please insert all fields into the form below.';
        }else{
            if(
    $pass1 != $pass2){
                
    $message ='Your password fields do not match.';
            }else{
                
    //securing the values of the variables
                
    $username preg_replace("#[^0-9a-z]#i","",$username);
                
    $fname preg_replace("#[^0-9a-z]#i","",$fname);
                
    $lname preg_replace("#[^0-9a-z]#i","",$lname);
                
    $pass1 sha($pass1);
                
    $email mysql_real_escape_string($email);
                
                
    //check duplicates
                
    $user_query mysql_query("SELECT username FROM members WHERE username='$username' LIMIT 1")or die("Could not check username");
                
    $count_username mysql_num_rows($user_query);
                
                
    $user_query mysql_query("SELECT email FROM members WHERE email='$email' LIMIT 1")or die("Could not check Email");
                
    $count_email mysql_num_rows($email_query);
                
                if(
    $count_username 0){
                    
    $message ='Your username already exists.';
                }else if(
    $count_email 0){
                    
    $message ='Your email already exists.';
                }else{
                    
    // insert users
                    
    $query mysql_query("INSERT INTO members (username, fname, lname, email, password, lastlogin, accounttype, emailactivated, joindate) VALUES('$username', '$fname', '$lname', '$email', '$password', '', '', '', now())")or die("Could not insert data.");
                    
    $member_id mysql_insert_id();
                    
    mkdir("users/$member_id",0755);
                    
    $message ='You have now been registered.';
                }
            }
    ?>
    body section
    Code:
    <div>
    Register to my site by filling in the fields below.
    	<p><?php print("$message");?></p>
    	<form action="register2.php" method="post">
    		<input type="text" name="username" placeholder="Username"/><br />
            <input type="text" name="fname" placeholder="First Name"/><br />
            <input type="text" name="lname" placeholder="Last Name"/><br />
            <input type="text" name="email" placeholder="Email Address"/><br />
            <input type="password" name="pass1" placeholder="Password"/><br />
            <input type="password" name="pass2" placeholder="Validate your password"/><br />
            <input type="submit" value="Register" />
    
    
    	</form>
    </div>
    Last edited by ershy; 11-14-2012 at 01:07 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You don't have an entry called user in your form. You'll never pass the first isset check without it. Isset should be given every item you expect to be provided with to verify they exist prior to useing them.

  • Users who have thanked Fou-Lu for this post:

    ershy (11-14-2012)

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks! I changed
    PHP Code:
    if(isset($_POST['username'])) 
    but it still died without firing off the form. I'm still a bit confused.
    Last edited by ershy; 11-14-2012 at 02:18 AM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Now you add a print. Currently the script generates no output so you cannot tell where you ended up. Add print $message; to the bottom of the script.

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I actually have a print at the top of the form. When I load the page on the server though, it never loads the form or the print.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I'm not talking about a print on the form, I'm talking about a print on the processing script register2.php. No matter the outcome of the script, it produces no output.


  •  

    Tags for this Thread

    Posting Permissions

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