Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: php login/registration

  1. #11
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I'd definitely say to contact you host for this info. For example, if phpmyadmin was already set up when you opened your hosting account, you might have never known these details.

    Your username and password are probably (but maybe not) the same as those you use to log in to phpmyadmin. The database name should be shown in your phpmyadmin panel. As for "server," different hosts have different ways of configuring them and different ways of allowing access from your sites.

    Once you have determined your database credentials, use them in place of the "server, username, password, database" in your code. However, for security reasons, always ********* them when you post your code here (or anywhere online).

    On a related subject, mysql_connect() does not accept the database and/or table name as an argument:
    PHP Code:
    // the fourth argument is (boolean)new_link, not the database name.
    // if you put anything there (other than FALSE), it will simply be interpreted as "true"
    // it won't throw an error, but it won't do what you expect, either.
    mysql_connect('servername','username','password','databasename');

    // this will have no result
    $r mysql_query("select * from table");

    // and this will return:
    // " No database selected. "
    print mysql_error();

    // leave 'databasename' _out_ of mysql_connect()
    // you need to use this after you connect:
    mysql_select_db('databasename');

    //and then you can continue with your queries 
    Last edited by traq; 06-20-2011 at 05:15 AM.

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

    Default

    Thanks for all your help everybody. I think I finally got the registration bit working. However there is another problem. For the page Thats meant to log them in I just get this.

    Fatal error: Can't use function return value in write context in /home1/keyboard/public_html/login.php on line 37

    The code is
    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";
       }
    }


       
    ?>
    .

    I know I'm not very good at this so thanks for your patience.
    Last edited by jscheuer1; 06-20-2011 at 11:33 AM. Reason: format code

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    is this:
    PHP Code:
    <form action="<? $_SERVER['PHP_SELF']."?login=true" ?>" method="POST">
    line 37?
    it should be written:
    PHP Code:
    <form action="<?php print $_SERVER['PHP_SELF']."?login=true"?>" method="POST">

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

    Default

    I'm still getting this error

    Fatal error: Can't use function return value in write context in /home1/keyboard/public_html/login.php on line 37

    I changed what you said. Any help is appreciated

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

    Default

    Try this, whoever wrote this didn't reopen the php tag correct after the html form.
    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";
       }
    }
    ?>

  6. #16
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Still coming up with the same error. I think I will find a new project to work on.

  7. #17
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    this does seem to be written a little sloppily. before giving up, however, could you let us know which line is line 37? That would certainly help with troubleshooting.

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

    Default

    Or how about the fact that they forgot the semicolon on this line and the echo
    PHP Code:
    <form action="<? $_SERVER['PHP_SELF']."?login=true" ?>" method="POST">
    Should be this
    PHP Code:
    <form action="<? echo $_SERVER['PHP_SELF']."?login=true"?>" method="POST">
    I agree that this is very poorly written. Not even sure how the person got this to work in the first place let alone post it somewhere for others to use. If you want a really good tutorial that uses proper coding practices and security features, check this youtube channel out and look for his login/registration videos - there are a few of them - http://youtube.com/betterphp

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
  •