Results 1 to 20 of 20

Thread: Register / Login

  1. #1

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Register / Login

    Ok, So I am just learning PhP, and I havent learned too much, but Im getting the basic Idea of it. I tend to work better when I have examples to look at.. Can someone help me out with some example code for a working user registration and Login page? I cant find any...Anywhere.
    You win some, you lose some.

  2. #2
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

  3. #3
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Register / Login

    Here is a basic login script. HTH

    PHP Code:
    <?php
    $username 
    $_POST['username'];
    $email $_POST['email'];

    if (!isset(
    $_POST['submit'])) { // if form hasn't been submitted to itself then show form

    ?>
    <html>
    <head>
    <title>Lintz's Test Login</title>
    </head>

    <body><center>
    <b><font size="6">Please enter your username and email address to login</font></b> 
    <p>
    <form method="POST" action="<?php echo $PHP_SELF;?>">
    <table border="1" style="border-collapse: collapse" bordercolor="#111111" width="580">
    <tr>
    <td width="580">
    <table border="0" cellpadding="1" width="100%">
    <td width="35%"><font face="Verdana" size="2"><b>Your Name:</b></font></td>
    <td width="65%"><input type="text" name="username" size="65"></td>
    </tr>
    <tr>
    <td width="35%"><font face="Verdana" size="2"><b>Email Address:</b></font></td>
    <td width="65%"><input type="text" name="email" size="65"></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><br>
    <input type="submit" value="Login" name="submit" style="font-family: Verdana; font-size: 10pt; font-weight: bold"></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>

    <?


    else {

    /*This is where you need to check the details the user has entered to make sure
    they match what is in your database*/

    if ($username == "UserName In Yr Database") {
    //This shows the user who has submitted the detials, what details have been submitted.
    echo "Thank you for logging in<p>";
    echo "Your username is $username and your email address is $email.";
    }

    else {
    echo "Login failed. Please check your details and try again";
    }

    }
    ?>

  4. #4
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Register / Login

    mine uses MySQL his doesnt...ur choice on wat u prefer

  5. #5
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Register / Login

    Ninja, I was a little lazy as I put a comment in saying to check the username entered is in his database.

  6. #6
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Register / Login

    o lol missed that part

  7. #7

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Register / Login

    Wow, Thank you alot...Yeah, I would like to Use Sql, Ill take a look at the examples you guys gave me in a minute....Is there one for registering you could show me an example of too?
    You win some, you lose some.

  8. #8
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Register / Login

    Ninja's example does that as well

  9. #9

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Register / Login

    Yes, I saw that, And thanks once again. I have one more thing I could use a little basic help on, Its alot easier to understand things with asking + examples then looking on all the sites I've been to. I just need some basics on Databases, Indexes, Auto Increments, and all that good junk...Surprisingly, I dont get it.
    You win some, you lose some.

  10. #10
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Register / Login

    php.net and mysql.com have good things and remember...google is ur friend

  11. #11
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: Register / Login

    indexes like array indexes? and auto increments like

    <?php
    if (x < 10)
    {
    x++;
    }
    echo "x";
    ?>

    ???? databases i dont really no but other ppl do

  12. #12

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Register / Login

    Yes, ive been using google, but the tutorials and anything I find are too general, They dont have specifics on how to actually read from the DB and stuff, but Im sure i can find it if i spend some more time on it...

    By indexes and Auto-Increments, I meant in the Database/Table itself....Like im going to be making a text-based RPG, And Its obviously going to use alot of tables....For now i think im going to be making one table, with all the info it in, And i need to know how to read/write from it so that i can look up the user's name and get their gold/army size....all that junk just from looking up their name.
    You win some, you lose some.

  13. #13
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Register / Login

    Try this.

    PHP Code:
    $sql "SELECT * from YourTable WHERE userID = '1'"//Tell database what to get     
    $result   mysql_query($sql) or die("Error getting user info<br>".mysql_error()); // Pulls what we want from the database 

    //Now loop through all records from query

    while ($UserDetails mysql_fetch_row($result)) {

    echo 
    "$UserDetails[0]<br>"//field one from table
    echo "$UserDetails[1]<br>"//field two from table
    echo "$UserDetails[2]<br>"//field three from table



  14. #14
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Register / Login

    Quote Originally Posted by psycopatchet69
    Yes, ive been using google, but the tutorials and anything I find are too general, They dont have specifics on how to actually read from the DB and stuff, but Im sure i can find it if i spend some more time on it...

    By indexes and Auto-Increments, I meant in the Database/Table itself....Like im going to be making a text-based RPG, And Its obviously going to use alot of tables....For now i think im going to be making one table, with all the info it in, And i need to know how to read/write from it so that i can look up the user's name and get their gold/army size....all that junk just from looking up their name.
    Post what your table will look like and we'll try and give you a general idea on how to structure it. Generally the smaller the tables the better as it can take a long time to search through a really large table.
    Don't Rate my posts.

  15. #15

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Register / Login

    Now can you please explain what that does? lol

    More specific - I have a table named Info, and in the table there are 3 field, Name, Gold, Army....Now, How do I Tell it to take name = Psycopatchet, and return me the gold and army size? And also, How to locate those values for maniplulation.
    You win some, you lose some.

  16. #16

    Thread Starter
    Hyperactive Member psycopatchet69's Avatar
    Join Date
    Sep 2004
    Location
    Grand Rapids, MI
    Posts
    256

    Re: Register / Login

    Ok, as an addon to my question(s), This may sound stupid..But in the "mysql_query($query,$link)" statement, I put a link to my database, right?
    You win some, you lose some.

  17. #17
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Register / Login

    A mod from my previous example.

    PHP Code:
    $sql "SELECT * from Info WHERE Name = 'Psycopatchet'"//Tell database what to get      
    $result   mysql_query($sql) or die("Error getting user info<br>".mysql_error()); // Pulls what we want from the database 

    //Now loop through all records from query 

    while ($UserDetails mysql_fetch_row($result)) { 

    echo 
    "Name = $UserDetails[0]<br>"//field one from table 
    echo "Gold = $UserDetails[1]<br>"//field two from table 
    echo "Army = $UserDetails[2]<br>"//field three from table 



  18. #18
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: Register / Login

    Quote Originally Posted by psycopatchet69
    Now can you please explain what that does? lol

    More specific - I have a table named Info, and in the table there are 3 field, Name, Gold, Army....Now, How do I Tell it to take name = Psycopatchet, and return me the gold and army size? And also, How to locate those values for maniplulation.
    User Table
    User ID = Auto increment
    Name = String
    Any other person details

    Info Table (you could probably think up a better name than that )
    User ID
    Gold = Integer
    Army = Integer?


    So your query will end up looking something like,
    SELECT GOLD, ARMY FROM INFO,USER WHERE USER.UID = INFO.USERID AND USER.NAME = "Some Fellars Name"
    Don't Rate my posts.

  19. #19
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Register / Login

    "Some Fellars Name", only us Aussies would use a phrase like that

  20. #20
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Register / Login

    http://phpfreaks.com have sum good tuts.... I learnt pagination from them.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

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



Click Here to Expand Forum to Full Width