Results 1 to 6 of 6

Thread: User Registration...

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default User Registration...

    I'm working on a user registration using PHP and MySQL. I have a database set up, called "ajuser" and a table set up called "userlogin".

    What's odd is that it goes through without any errors, but just doesn't work. So, here's the code:

    PHP Code:
    $name $_POST['name'];
    $user $_POST['user'];
    $pass $_POST['pass'];
    $pass_conf $_POST['pass_conf'];
    $email $_POST['email'];
    $ip $_SERVER["REMOTE_ADDR"];

    if( 
    $name == false || $user == false || $pass == false || $pass_conf == false || $email == false) {
        echo 
    '<p>Please Fill In All Fields</p>';}

    else if ( 
    $pass != $pass_conf) {
        echo 
    '<p>Password and Confirm Password fields do not match. Fields ARE case sensitive!</p>';}
        
    else {
        
    $connection mysql_connect($host$dbuser$dbpass);
        
    $db mysql_select_db($dbname$connection);
        
    $sql "INSERT INTO userlogin (name,username,password,email,ip) VALUES ($name$user$pass$email$ip)";
        
    $result mysql_query($sql);
        echo 
    '<p>Thanks for registering. You may now login.</p>';} 
    Now, it shows the "Thanks for Registering" message...but when I look at the table, it's empty!

    What's wrong?

  2. #2
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Alright, I see no one's looking at this question? Well, I updated the code:

    PHP Code:
    $name $_POST['name'];
    $user $_POST['user'];
    $pass $_POST['pass'];
    $pass_conf $_POST['pass_conf'];
    $email $_POST['email'];
    $ip $_SERVER["REMOTE_ADDR"];

    if( 
    $name == false || $user == false || $pass == false || $pass_conf == false || $email == false) {
        echo 
    '<p>Please Fill In All Fields</p>';}

    else if ( 
    $pass != $pass_conf) {
        echo 
    '<p>Password and Confirm Password fields do not match. Fields ARE case sensitive!</p>';}
        
    else {
        
    $connection mysql_connect($host$dbuser$dbpass);
        
    $db mysql_select_db($dbname$connection);
        
    $sql "INSERT INTO `userlogin` ('name','username','password','email','ip') VALUES ($name$user$pass$email$ip)";
        
    mysql_query($sql);
        echo 
    '<p>Thanks for registering. You may now login.</p>';} 

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The only thing I can see is that your line:
    PHP Code:
    $sql "INSERT INTO `userlogin` ('name','username','password','email','ip') VALUES ($name$user$pass$email$ip)"
    Should be:
    PHP Code:
    $sql "INSERT INTO `userlogin` ('name','username','password','email','ip') VALUES ('$name', '$user', '$pass', '$email', '$ip')"
    Note the ' ' around the values. I think that will make it work, hope it helps

  4. #4
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    In my queries I use that format and it works:
    Code:
    $sql = "insert into userlogin values('$name', '$user', '$pass', '$email', '$ip')";
    Try it! And I hope it works!!
    Have a Happy New Year!
    Last edited by costas; 01-02-2007 at 02:09 PM.

  5. #5
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Costas - did you leave the double quotes on the end off on purpose? Or should it be:

    PHP Code:
    $sql "insert into userlogin values('$name', '$user', '$pass', '$email', '$ip')"
    ?

  6. #6
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No, the quotes must be there (I corrected it)! Without them the query wont be only the "insert into userlogin values('$name', '$user', '$pass', '$email', '$ip')" but also all the rest code until the next "!!

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
  •