NA
CONSOLE PC
OP
AU
Rep:
55%
Member
Taken from the Australian CyberGamer Forums. [HERE]


Create a Basic PHP/MySQL Membership System - Part 1

Hey guys. For those of you who want to create their own clan website or something similar then these tutorials are perfect for you. Over a series of tutorials, I am going to teach you how to create a basic membership system using PHP and MySQL with a little bit of JavaScript on the side.

Note: If you want to develop this on your own computer then you will need to install XAMPP. It's easy to install and allows you to develop scripts locally without the need for online hosting. I will assume you are using XAMPP throughout these tutorials.


Step 1 - Creating a Database

Using phpMyAdmin (http://localhost/phpmyadmin), create a new database, as seen below:
[img]http://www.cgdata.com/users/17376/f/368/createdatabase.png[/img]

Now let's create some tables in our new database. Copy and paste the following code (click the spoiler to view the code) into the SQL queries box (as seen in the picture below):
SPOILER: Click to view

[img]http://www.cgdata.com/users/17376/f/369/createtables.png[/img]

Step 2 - Creating a Basic HTML Page

All of our pages will be using this template (click the spoiler to reveal the code):
SPOILER: Click to view

Step 3 - Creating the Config File

Create a new file called config.php. The config file will hold various details and functions which are necessary for our system to function correctly. You will only need to edit your database details which are at the top of the config file (click the spoiler to reveal the code):
SPOILER: Click to view

Step 4 - Creating the Registration Form

Create a page called register.php using the basic template above and add this HTML form between the <body> tags (click the spoiler to reveal the code):
SPOILER: Click to view

And now, for the PHP code, which will be added above the <html> tag at the top of the page. I have added comments throughout the code to help you understand what is going on (click the spoiler to reveal the code):
SPOILER: Click to view

Step 5 - The Final Product

If you don't feel like piecing the bits of code together then copy and paste this. This is what the completed registration page should look like (click the spoiler to reveal the code):
SPOILER: Click to view




In this part I will be showing you how to create the login script so that users can actually log in after registering. We will also be creating a members page that only logged in users can view.


Step 1 - Creating the Login Form

Create a page called login.php using the basic template from the previous tutorial and add this HTML form between the <body> tags (click the spoiler to reveal the code):
SPOILER: Click to view

And now, for the PHP code, which will be added above the <html> tag at the top of the page (click the spoiler to reveal the code):
SPOILER: Click to view

Step 2 - Simple JavaScript Form Validation

By using a small piece of JavaScript code we can check if the user has left out any of the fields in the login form, without reloading the page! Add his code between the <head> tags (click the spoiler to reveal the code):
SPOILER: Click to view

Step 3 - The Final Product (Login Page)

This is what your login.php page should look like after piecing together all of the code (click the spoiler to reveal the code):
SPOILER: Click to view

Step 4 - Creating a Members Page

Create a page called members.php. This page will be used to display members only content, meaning that the user will have to be logged in to view it. We do this by simply adding the check_login() function we have stored in our config file.
SPOILER: Click to view
Quote
Downvote
Like
7.1 years ago

View All Featured Upcoming PC Tournament:
Advertisement:
Advertisement:
PUBG?
I want to play in CG PUBG competitions
I only play PUBG casually
I dont play PUBG
1203 Votes