Class

Projects

  • Free MP3s on Last.fm

Sponsors

PHP / MySQL Chatroom Part 1/5 - Setting Up Our Database Using phpMyAdmin

Printer-friendly versionPrinter-friendly versionSend to friendSend to friend

PHP / MySQL Chatroom Part 1/5 - Setting Up Our Database Using phpMyAdmin

phpMyAdmin is a program written in PHP that allows us to perform basic tasks to our database simply and easily. It is important to note that phpMyAdmin is NOT our database, but instead a tool to view and manage it.

If you are working in xampp, phpMyAdmin is already installed and you can access it from http://localhost/phpmyadmin from your web browser. If you have your own server online, your hosting company may have already set it up and sent you access to it. If not, you can install it from the documentation at http://www.phpmyadmin.net.

If you are working locally you shouldn't need to login unless you manually set one up. Once you are in your system, depending on your permissions, you should have the access to create a new database, or edit a current one.

Like in the image above (click to enlarge). Let's create a database called "chat" from this first screen. You can leave the other options default and click 'Create'.

On the left now you should see that you are working within the "chat" database. From here we can add as many tables to this database as we need. The first table for this chat system will be a table to keep track of users.

In the area that says "Create new table on database chat", we are going to create a table named "users". We will define 10 fields (we can always add fields later or ignore unused ones).

The next screen you get to will be a list of each of those fields, ready to be told what they are and how to act. Our table will have the following fields: id, username, password, email, fname, lname.

These should be fairly explanitory, we need the username and password so the user has a way to login, the fname and lname so we can politely talk to the user by their real names, email in case we need to contact them, and lastly, we need an id field. This field is very important as it will be a unique field that will identify each user in our table by a number.

The id field will be our first field. Set the type to INT, then we need to make sure the Auto_Incriment (A_I) option is checked and the Index is set to Primary. You may need to scroll to the right to see these options.

We will then make a field for username, password, email, fname, and lname. Each of those fields will be set to type="Varchar". And will have a length/value of 100.

The INT type is simply an integer number. We checked the auto-increment box because everytime we add a new user, it will automatically number the row (1,2,3...). We then  told it to be the primary key, because that will be the main identifier of this table.

The varchar type is simply a string type that can have no more than 255 characters. This field type must always have a length set so we set 100 for all of them because they shouldn't need to have more than 100 characters each.

Once you have all the fields described as above, scroll down and click the save button.

So now your table structure is all set up. It is ready for us to add a row into it. We do this using the insert page, on the top you should see a row of tabs, one being insert. Click the insert button to get to a page where we can add a new row in our database.

Here you can fill in what you want your username to be, password as well as your first name, last name, and email address. You don't wan't to fill anything in the ID field (we told that to work automatically). Once you filled out one of the rows, click the "Go" button.

Now that you have an entry in your table, you can click the top "Browse" tab and verify the rows. Up next, we will create a php form where the user will fill out a username and password. Our code will check to see if it exists in this newly created database.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.