PHP/MySQLi Creating a Forum - Part 13 - Users & Registering
Submitted by Yorkiebar on Wednesday, January 22, 2014 - 08:44.
PHP/MySQLi Creating a Forum - Part 12 - Listing Messages and Threads
Introduction:
This tutorial will be continuing my series of creating a forum in PHP/MySQLi/HTML. This part will be covering users.
Pre-creation:
First you will need a host for your PHP, either a web host or localhost is fine but you will need PHP and MySQL(i) capabilities.
Also, this will not be covering creating users, or styling the pages. For the purpose of using the logged in users username, we will be using $_SESSION['username']; from my login script, you can find that tutorial on my profile page.
Obviously you will also need to go through all the previous parts of this tutorial series which can all be found on my profile tracking page.
Users Table:
To start, we need a users table. Create the table named 'users' with the following information...
id - INT - 5 Length - Primary Key - AI
username - VARCHAR - 255 Length
password - VARCHAR - 255 Length
Register:
Next lets make a register page, I will call mine 'register.php'. In that we first need a HTML form...
PHP:
To process this, we want to check if the information is valid first. If it is, we want to create an MD5 encrypted hash version of the password, check if the user is already taken and it if it is available, add it as a new row to the table with the encrypted password (MD5 Hash). We also output the outcome...
- <form action='register.php' method='POST'>
- <table>
- <tbody>
- <tr>
- <td>Username: </td><td><input type='text' name='user' /></td>
- </tr>
- <tr>
- <td>Password: </td><td><input type='password' name='pass' /></td>
- </tr>
- <tr>
- <td></td><td><input type='submit' value='Register' name='reg' /></td>
- </tr>
- </tbody>
- </table>
- </form>
- <?php
- $pass = $_POST['pass'];
- $user = $_POST['user'];
- echo 'That username is already taken.';
- }else{
- if ($qq) {
- echo 'Registered successfully!';
- }else
- echo 'Failed to register.';
- }
- }
- ?>
Add new comment
- 67 views