Change background image
  1. What's up? I see you're viewing as a Guest. How about registering, it only takes like 2 minutes. This will enable you to do more on our forum and stay updated.

How to make a simple registration form with a Database

Discussion in 'PC General' started by Nuke547, Jul 11, 2011.

Thread Status:
This thread is more than 180 days old.
  1. Nuke547

    Nuke547 Junior Member Member

    This tutorial is supposing you have XAMPP.

    The first thing you want to do, is make a a database. Lets call it "register".

    Then in the database, create a table called "users".
    In that, create 2 new tables within Users names "username" and "password".

    Once you have it all setup, start you php file. To connect to the database, use this code(there will be no password for the root username, and also, $con is a variable):
    Code:
    <?php
    $con = mysql_connect("localhost","root","");
    ?>
    To select your db, you use this code.

    Code:
    mysql_select_db("users", $con);
    Once you have this, the total php code is

    Code:
    $con = mysql_connect("localhost","root","");
    mysql_select_db("my_db", $con);
    
    Now lets work on the registration form, we'll just do a simple username and password.
    Here is how you would do it.

    Code:
    <form method="post" action="register.php"> //the action determines what page you will go to when you press submit
    Username: <input type="text" name="user"> //Will create a textbox for them to type in there username
    Password: <input type="pasword" name="pass"> // will create a textbox, but text will show up as dots
    <input type="submit"> //Submit button
    
    So now that we have our registration form, it will go to register.php, and we can go to the part where it inserts the information into the database.

    This is what inserts it.

    Code:
    $registerl="INSERT INTO users (username, password) // Says where to inset them
    VALUES
    ('$_POST[user]','$_POST[pass]')"; //The values of what to put into the tables
    
    And thats it. That will create your registration form, and if you look in your database, you will see the username and password you put in the registration form. You can put an encryption on the password if you would like to, but thats basically it. In the future, I will make a login tutorial in the future, but thats how you make a registration!
  2. 3nvisi0n

    3nvisi0n The R3v0lu710n Super-Mod

    This works for a basic way however there is a huge security flaw in it. Your code can be exploited with a SQL Injection.
    Code:
    $registerl="INSERT INTO users (username, password) // Says where to inset them
    VALUES
    ('$_POST[user]','$_POST[pass]')"; //The values of what to put into the tables
    
    You put $_POST and $_POST[pass] directly into the SQL statment without caring what a user put(no safety). So a malicious user could come along and enter a malicious string allowing them to do damage. Also perhaps in the future you can show us how to look for errors in the insert, or notice if two users have the same username?
  3. Nuke547

    Nuke547 Junior Member Member

    That will come in future tutorials
Thread Status:
This thread is more than 180 days old.

Share This Page