Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: php login/registration

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default php login/registration

    I found a registration and login code for php and sql on the internet however when I tried to use it , it wouldn't work. Should I just post the entire scipts here?
    thanks for any help.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Post a link to the code that you found. And tell us what errors you're getting.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    http://www.astahost.com/info.php/php...ipt_t2659.html

    This is where I found the code. I'm not even sure if I configered it right so here's the code I copied

    This is the registerUser.php file
    PHP Code:
    <?php
    if ($_GET['register'] == 'true') {
       
    registerUser();
    }

    function 
    registerUser() {
       
    mysql_connect('server''username''password''database');
       
    $username $_POST['username'];
       
    $password md5($_POST['password']);

       
    $sql "INSERT INTO tblUsers (fldUsername, fldPassword) VALUES ($username$password);";

       
    mysql_query($sql);
    }
    ?>

    <html>
       <head>
           <title>Registration</title>
       </head>
       <body>
           <form action="<?php $_SERVER['PHP_SELF']."?register=true" ?>" method="post">
               Username: <input type="text" name="username">
               Password: <input type="password" name="password">
               <input type="submit" value="Register">
           </form>
       </body>
    </html>
    and this is the page login.php

    PHP Code:
    <?php
       
    if ($_GET['login'] = true) {
           
    loginUser();
       } else {

    ?>


    <html>

       <head>
           <title>Login</title>
       </head>
       <body>
           <form action="<? $_SERVER['PHP_SELF']."?login=true" ?>" method="POST">
               Username: <input type="text" name="username"><br>
               Password: <input type="password" name="password"><br>
               <input type="submit" value="Login">
           </form>
       </body>
    </html>
    ?>
    }
    <?php
       
    function loginUser() {
       
    session_start();

       
    $username $_POST['username'];
       
    $password $_POST['password'];

       
    $sql "SELECT fldId, fldPassword FROM tblUsers WHERE fldUsername = '$username';";

       
    $result mysql_query($sql);

       
    $row mysql_fetch_assoc($result);

       if (
    md5($password) = $row['fldPassword']) {
           
    $_SESSION['loggedin'] = true;
           echo 
    "Logged In";
       }
    }


       
    ?>
    When I try to test making an account I click the submit button but nothing happens. Note- I did make the sql database.
    Thanks for any help
    Last edited by jscheuer1; 06-17-2011 at 01:53 PM. Reason: format code

  4. #4
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You're not actually connecting the the database
    PHP Code:
    mysql_connect('server''username''password''database'); 
    The info for the connect needs to be changed to the login credentials for your database. The script simply provides your what needs to go in the connect but you need to change it to your needs.

  5. #5
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    This is the code used to make the sql database

    CREATE TABLE tblUsers (
    fldId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    fldUsername VARCHAR(40) NOT NULL,
    fldPassword VARCHAR(40) NOT NULL
    );

    Is that what you're saying? I'm still really confused. Thanks for any help.

  6. #6
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    No, you need to change the server, username, password, database to what your login credentials are for your database.

  7. #7
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    How do I do that?

  8. #8
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    How do you log in to your database now? Are you on localhost or paid hosting? Either way the username, password and such is the info you need to replace what I told you. If you don't have a database setup yet then you have a lot more work to do than what I told you.

  9. #9
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Post

    I am using helio host which has php enabled and sql. I just followed the instructions on the page and used that code up the top of this thred in phpmyadmin to make a database. Is this what you're saying. Also, I don't know what I have to change in the code that you pointed out. I'm very new to this so can you please try to explain it to me simply. Thanks for any help.

  10. #10
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    I am not sure how many different ways you want me to tell you the same thing. I have showed you and told you which items to change 3 times now.
    When you setup your database you would have had to create a username and password for the database, use that info in place of the word username and password in the connect line I showed you.

    Maybe your username is transformers and the password is optimusprime, I don't know, only you do. Then change the word database in the connect line to what ever you named the database. As for the word server, that is slightly trickier and you may want to contact you host to get that info since you are having such a hard time figuring this out.

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
  •