How to add new fields to a table and a warning about modifying existing tables

Description

Collection: PHP Programming BasicsChapter: Working With the (MySQL) Database

Transcript

So let's do something practical with our newfound knowledge of how to connect the database up with PHP. Now, in one of our previous examples earlier on in this series, we created a log in form in order to allow people to log in to a specific part of the site that they couldn't access otherwise. And the way we stored username and passwords was in an array, but we can use a database for that same information.

So what we're going to do in this next step is actually take that information that was in the array and add it to our table, the people table that we've been working with, in order to allow our three users to log in. Our first step is going to be adding two additional columns to our people table' for username and password. So let's go over to PHPMyAdmin and in the people table in our my_database database that we created earlier on in this series, what we want to do is click the structure tab and then in here there's this simple form to add a number of fields at a particular point in the list of columns.

So you see that there is a particular order to columns here. Most of the time this order doesn't matter so much because when we query the database we're going to be accessing the particular columns by name instead of by a particular order; however, when we're browsing data inside of PHPMyAdmin it can be easier to see the important data if it's near to the top because those will show more towards the left when we're browsing. For our username and password though, let's go ahead and simply leave it as its default to add the fields at the end of the table.

Now, we'll we want to add two so I'm going to change this one to two, and then I'll click the go button. Now, here we have our two columns, one ...

When you have an active membership, you will be able to see your progress here.

Skill focus: ProgrammingSkill level: Beginner - Advanced

In this collection, we walk you through everything you need to know to build rich PHP applications and work with PHP code in Drupal. These videos are designed to bridge the gap between Drupal site builders and programmers. We guide you gently through the basics of PHP, and work our way into building more and more complicated scripts. In our final example we build a custom CMS, which will help you understand the architecture of Drupal while flexing your new PHP skills in a practical way.

To follow along with these videos, you will need a web environment set up on your computer. Follow the videos in Setting Up a Web Environment With Drupal to get an environment set up on Windows, OSX (Mac) or Linux.

Some of the key points we'll be covering include:

How to work with variables and functions

How to use logic in PHP like if…then statements and looping

How to build forms in PHP

How to store persistent data in sessions

How to work with MySQL

How to build a simple CMS from scratch

Who this collection is for

This collection is for those that want to learn PHP programming. You may want to learn PHP to work with Drupal in particular, but what you learn will be useful for any project you work on requiring a background in PHP.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: