Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default Not adding to the DB [PHP]

    When you press register, it doesn't add the contents to the database. All it does is refresh the page.

    PHP Code:
    <?php

    if($logged['in'] == 1){
        
    header("Location: index.php");
    }

    if(
    row_exists('users','ip',$ip)){ ?>
        Your IP ($ip) has already been registered with.
    <?php }

    else{
        if(
    $_GET["action"] == "register"){
            
    $username clean($_POST['username']);
            
    $email clean($_POST['email']);
            
    $password clean($_POST['password']);
            
    $cpassword clean($_POST['cpassword']);
            
            
    $errors 0;
            
    $error_message '';
            
            if(empty(
    $username) || empty($email) || empty($password) || empty($cpassword)){
                
    $errors++;
                
    $error_message 'All fields must be filled in.';
            }
            
            if(
    row_exists('users','username',$username)){
                
    $errors++;
                
    $error_message 'That username is already taken.';
            }
            
             if(
    row_exists('users','email',$email) || !is_valid_email($email)){
                 
    $errors++;
                
    $error_message 'That email is alreayd in use or is incorrect.';    
             }
             
             
    $password enc($password);
             
    $cpassword enc($cpassword);
             
             if(
    $password != $cpassword){
                 
    $errors++;
                 
    $error_message 'The two passwords you entered do not match.';
             }
             
             if(
    $errors 0){
                 
    $insert mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`ip`,`joindate`,`jointime`) VALUES ('".$username."','".$password."','".$email."','".$ip."','".$date."','".$time."')");
                 
                 
    $subject "Welcome to willSystem";
                 
    $body "Thanks for joining (test message from willSystem demo.)";
                 
    send_mail($email,$subject,$body);
                 
                 
    ?>

    Thanks for joining, you may now <a href="login.php">login</a>.
                 
    <?php

    exit();
             } else{
                 echo 
    $error_message;
             }
             
        }

    ?>
    <form method="post" action="?action=register">
    Username<br />
    <input type="text" name="username" value="<?=$username?>" maxlength="12"><br /><br />
                     
    Email<br />
    <input type="text" name="email" value="<?=$email?>"><br /><br />
                     
    Password<br />
    <input type="password" name="password"> Confirm <input type="password" name="cpassword"><br /><br />
                     
    <input type="submit" name="register" value="Register"><br /><br />
                     
    All fields are required.
    </form>

    <?php
    }
    ?>
    Thanks for any help given.

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Hi,

    Could you please try this code so we can find out if there are any errors with your MySQL query/database.

    PHP Code:
    <?php

    if($logged['in'] == 1){
        
    header("Location: index.php");
    }

    if(
    row_exists('users','ip',$ip)){ ?>
        Your IP ($ip) has already been registered with.
    <?php }

    else{
        if(
    $_GET["action"] == "register"){
            
    $username clean($_POST['username']);
            
    $email clean($_POST['email']);
            
    $password clean($_POST['password']);
            
    $cpassword clean($_POST['cpassword']);
            
            
    $errors 0;
            
    $error_message '';
            
            if(empty(
    $username) || empty($email) || empty($password) || empty($cpassword)){
                
    $errors++;
                
    $error_message 'All fields must be filled in.';
            }
            
            if(
    row_exists('users','username',$username)){
                
    $errors++;
                
    $error_message 'That username is already taken.';
            }
            
             if(
    row_exists('users','email',$email) || !is_valid_email($email)){
                 
    $errors++;
                
    $error_message 'That email is alreayd in use or is incorrect.';    
             }
             
             
    $password enc($password);
             
    $cpassword enc($cpassword);
             
             if(
    $password != $cpassword){
                 
    $errors++;
                 
    $error_message 'The two passwords you entered do not match.';
             }
             
             if(
    $errors == 0){
                 
    $insert mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`ip`,`joindate`,`jointime`) VALUES ('".$username."','".$password."','".$email."','".$ip."','".$date."','".$time."')") or die( mysql_error() );
                 
                 
    $subject "Welcome to willSystem";
                 
    $body "Thanks for joining (test message from willSystem demo.)";
                 
    send_mail($email,$subject,$body);
                 
                 
    ?>

    Thanks for joining, you may now <a href="login.php">login</a>.
                 
    <?php

    exit();
             } else{
                 echo 
    $error_message;
             }
             
        }

    ?>
    Please reply with any errors that occur (if any).

    Also, if your if statement is meant to compare to values, remember to use two equals signs and not one. (See "if($errors = 0)"). This may be the cause of your error, I am not sure until you can report back any errors.

    Thanks,
    Invent
    Last edited by Invent; 25-07-2008 at 03:05 AM.

  3. #3
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    http://kolzy.com/ws/register.php

    Doesn't give out an error.

  4. #4
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Please see my edit.
    That probably won't fix your issue, so I'll try to scan through your code now.
    Last edited by Invent; 25-07-2008 at 03:07 AM.

  5. #5
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Quote Originally Posted by Invent View Post
    Please see my edit.
    That probably won't fix your issue, so I'll try to scan through your code now.
    Oh my god I love you! Thanks a hundred times. (it worked obv)

  6. #6
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Ah, fantastic! Good to hear your problem is fixed

  7. #7
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    Now there's a problem with the login page. It says that "the entered password doens't match the password of that user." When it actually does.

    PHP Code:
    <?php 

    if($logged['in'] === 1){
        
    header("Location: index.php");
    }

    if(
    $_POST['login']){
        
    $username clean($_POST['username']);
        
    $password clean($_POST['password']);
        
    $password enc($password);
        
        
    $errors 0;
        
    $error_message '';
        
        if(empty(
    $username) || empty($password)){
            
    $errors++;
            
    $error_message 'Both fields must be filled in.';
        }
        
        if(!
    row_exists('users','username','$username')){
            
    $errors++;
            
    $error_message 'That user does not exist.';
        } else{
            
    $query mysql_query("SELECT `id`, `username`, `password` FROM `users` WHERE `username` = '".$username."' LIMIT 1");
            
    $u mysql_fetch_object($query);
        }
        
        if(
    $u->password_reset == $password){
            
    $c_pass $u->password_reset;
            
    $update mysql_query("UPDATE `users` SET `password`='".$c_pass."', `password_reset`='' WHERE `id`='".$u->id."' LIMIT 1");
        } else {
            
    $c_pass $u->password;
            
    $update mysql_query("UPDATE `users` SET `password`='".$c_pass."', `password_reset`='' WHERE `id`='".$u->id."' LIMIT 1");    
        }
        
        if(
    $password != $c_pass){
            
    $errors++;
            
    $error_message 'The entered password does not match the password of that user.';
        }
        
        if(
    $errors == 0){
            
    $_SESSION['id'] = $u->id;
            
    $_SESSION['username'] = $u->username;
            
    $_SESSION['password'] = $u->password;
            
            
    header("Location: index.php");
        } else{
            echo 
    $error_message;
        }
            
        }
    ?>

  8. #8
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Hi,

    As a method of debugging, could you please alter the script (where it would usually output "the entered password doens't match the password of that user") so that it outputs the value of $password against the value of $c_pass. (EG: "echo ( $password . ' > ' . $c_pass )"). This will help me find out if the variables are actually equal to each other or if one is incorrect.

    Thanks,
    Invent
    Last edited by Invent; 25-07-2008 at 03:18 AM.

  9. #9
    Join Date
    Dec 2007
    Location
    Toronto, Ontario, Canada
    Posts
    689
    Tokens
    0

    Default

    9c5c7e79a2d17ca57911871290a4e8a6 > The entered password does not match the password of that user.
    That's what it says (using the code you gave). Would you want me to un-encrypt the password?

  10. #10
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Hi,

    Sorry, please use this code and report back the outputted data (so I know the exact issue):

    PHP Code:
    <?php 

    if($logged['in'] === 1){
        
    header("Location: index.php");
    }

    if(
    $_POST['login']){
        
    $username clean($_POST['username']);
        
    $password clean($_POST['password']);
        
    $password enc($password);
        
        
    $errors 0;
        
    $error_message '';
        
        if(empty(
    $username) || empty($password)){
            
    $errors++;
            
    $error_message 'Both fields must be filled in.';
        }
        
        if(!
    row_exists('users','username','$username')){
            
    $errors++;
            
    $error_message 'That user does not exist.';
        } else{
            
    $query mysql_query("SELECT `id`, `username`, `password` FROM `users` WHERE `username` = '".$username."' LIMIT 1");
            
    $u mysql_fetch_object($query);
        }
        
        if(
    $u->password_reset == $password){
            
    $c_pass $u->password_reset;
            
    $update mysql_query("UPDATE `users` SET `password`='".$c_pass."', `password_reset`='' WHERE `id`='".$u->id."' LIMIT 1");
        } else {
            
    $c_pass $u->password;
            
    $update mysql_query("UPDATE `users` SET `password`='".$c_pass."', `password_reset`='' WHERE `id`='".$u->id."' LIMIT 1");    
        }
        
        if(
    $password != $c_pass)
        {
            
            echo ( 
    $password ' > ' $c_pass );

        }
        
        if(
    $errors == 0){
            
    $_SESSION['id'] = $u->id;
            
    $_SESSION['username'] = $u->username;
            
    $_SESSION['password'] = $u->password;
            
            
    header("Location: index.php");
        } else{
            echo 
    $error_message;
        }
            
        }
    ?>
    You're saying $password DOES equal $c_pass so it should output for example, (lets say the password was "lol") the code should output "lol > lol". If not, the issue will become apparent.

    Thanks,
    Simon
    Last edited by Invent; 25-07-2008 at 03:24 AM.

Page 1 of 2 12 LastLast

Posting Permissions

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