Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Preparing your database

From: Validating and Processing Forms with JavaScript and PHP

Video: Preparing your database

Sometimes, you don't want to send the information to an email address. It can be unreliable and it's not easy to aggregate the data. In that case, it's better to push the information to a database. Most servers come with some implementation of the popular My SQL database. And it's pretty easy to use since the commands are fairly readable. This isn't designed to be a full database course. We'll just be talking about form implementation. So for more information, make sure you check out PHP with my SQL Essential Training, and for more SQL information, check out My SQL Essential Training.

Preparing your database

Sometimes, you don't want to send the information to an email address. It can be unreliable and it's not easy to aggregate the data. In that case, it's better to push the information to a database. Most servers come with some implementation of the popular My SQL database. And it's pretty easy to use since the commands are fairly readable. This isn't designed to be a full database course. We'll just be talking about form implementation. So for more information, make sure you check out PHP with my SQL Essential Training, and for more SQL information, check out My SQL Essential Training.

So, we've got a do a little bit of set-up. You're going to need to get credentials that give you access to the database. That usually involves creating the database, which you can do either through SSH or your host control panel. There's a lot of different control panels, and how you get to this varies from server to server. So I'm going to assume you already created a database. If you want to learn how to do that in some popular control panels, like C panel, Plesk or One in One, check out my course on managing a hosted website. You're going to end up with four pieces of data. The first one is the host name and here I place it in a bearable called host.

Some databases are hosted on servers other than your main domain. So the host name is going to be the url of the website with the database. If it's hosted in the same server as your site, you can use the keyword localhost. Databases are accessed with a username and password combination, so you'll need both of these in order to be able to post your data. I've created a variable called user and password here to store that information. Finally, you'll need the name of the database. I've called mine storeform. It's customary to place these on a separate PHP file and include them in your current docment.

The reason for this, is that you're probably going to want to use these on several files. So I've created this file, and it's called log_formdb.php. You can call yours wherever you want. I've placed this file on my server in the same folder as all my other files. Now, I won't be including this file in the exercise files for security reasons, but it's easy enough for you to create your own. In addition to creating a database, you'll also need to create a table. Think of a table as spreadsheets where your data is stored. You usually create tables with a control panel, like PHP MyAdmin, SSH or some other dedicated program. I'm going to show you how to do with PHP MyAdmin.

This my server's administration screen, and I've already created the database. But I need to create the table. So I'm going to click on this icon right here, and it will launch the PHP MyAdmin program. It's really common to see that program installed in a bunch of different hosts. So from here, I can hit create table, and in here I can give it a name. I'm going to call this form_info and then I need to create a number of fields. Now at first this program gives me two columns. The first column is usually a unique ID for the table.

So I'm going to call this form info_id. And I need to tell it what type of file this is going to be. Its already prechosen integer for me and that's going to work fine. This is going to be just an integer number that's going to be 11 units maximum. That's a lot of data base entries. Now you want to make this file the primary index, every database needs at least one primary index. You also want to check this check box called auto increment as you create new entries into this stable the ID number will automatically increment to show you've got new items on your table. The next field I'm going to create is a timestamp.

I'm going to call this one, forinfo_ts for timestamp, and this one's going to be a date and time. Notice there's a date area right here, and right over here under date and time there's one called date time, that's the one I'm going to use. You don't need to specify the length of a date time, there's a default length for that type of field. I know I'm going to need some additional columns, so I can save this or add a number of other columns. I'm going to need six additional columns, so I'll type that in, and select go. So now you can see there's additional columns, now it's switched to a horizontal layout here, but, it's pretty much the same as we saw before. I'm going to make these variables the same as the names in my PHP files. They don't really have to be, but it's just more convenient. Next one's going to be my name.

Obviously that's going to store my name. Usually when you store textual information, you can choose a type call varchar, it means a variable amount of characters. And after that, you tell it how many characters this should have. So for a name, since our name's going to be a first name and last name, I'm going to guess about 70 characters will be the same to hold any type of name. Now next, I'm going to enter my password. My password is also going to be a variable character. This one's going to be 60 characters long. That's because I'm going to take whatever the user types and then encrypt and add a sol to it. We'll talk more about that later.

60 characters should be enough to hold that. I'll add a section for my comments. Now my comments needs to be really long, so I'm going to choose from here, this type called, Text. I don't have to choose length or values when I enter a type of text. Next, I'm going to type in the reference, that's going to be another varchar, and I'm going to hold 15 characters. Then it'll be Favorite Music and again a varchar, 15 characters. Finally, I need to make a request type, and again, varchar 15 characters long. So, that should do it for my table.

I'm going to hit Save and it will create my database. So, there it is. And I can come over here and click on the database, and if I have any values, I can check on this browse part. Right now, this table's empty, so it's not letting me click on that. You can see the structure is complete, it looks really good, and if I want to, I can start putting values into this database. You can do that by clicking Insert here, but we're going to fill it out with our form. So, working with tables requires a little bit of set up on your part. And you are going to need to check out how your host handles database creation.

Once you have a database, you have the ability to store a number of records, and will later be able to query the database for any type of information you need about your users

Show transcript

This video is part of

Image for Validating and Processing Forms with JavaScript and PHP
 
Expand all | Collapse all
  1. 3m 36s
    1. Welcome
      1m 9s
    2. What you should know
      1m 2s
    3. Using the exercise files
      1m 25s
  2. 12m 50s
    1. Understanding forms
      2m 2s
    2. Working with form fields
      7m 4s
    3. Using the form tag
      3m 44s
  3. 19m 23s
    1. Using input validation
      2m 10s
    2. Adding required fields and placeholders
      1m 31s
    3. Constraining numeric and date fields
      2m 32s
    4. Accepting multiple entries
      1m 41s
    5. Limiting uploads by MIME types
      2m 35s
    6. Assisting text input with a datalist
      1m 55s
    7. Constraining with regular expression patterns
      6m 59s
  4. 42m 13s
    1. Accessing forms
      3m 57s
    2. Looking up form elements
      3m 35s
    3. Handling focus changes
      2m 47s
    4. Detecting the onchange event
      4m 31s
    5. Using the selectedIndex property
      2m 30s
    6. Dynamic validation with regular expressions
      7m 0s
    7. Creating a generic input validation function
      4m 31s
    8. Validating in older browsers with Modernizr
      7m 32s
    9. Interrupting form submission with onsubmit
      5m 50s
  5. 15m 20s
    1. Understanding jQuery
      3m 47s
    2. Validating on submit with jQuery
      3m 45s
    3. Building interactive jQuery validation
      2m 34s
    4. Using the jQuery Validation plugin
      5m 14s
  6. 32m 57s
    1. Communicating with PHP servers
      2m 27s
    2. Retrieving data from superglobals
      8m 18s
    3. Using server-side validation
      4m 59s
    4. Adding in-page validation
      5m 22s
    5. Mirroring input data back to the user
      7m 46s
    6. Sanitizing form input
      4m 5s
  7. 43m 29s
    1. Mailing form data
      8m 28s
    2. Understanding file uploads
      3m 1s
    3. Uploading files
      9m 20s
    4. Processing form data with AJAX
      8m 14s
    5. Preparing your database
      5m 50s
    6. Pushing data
      8m 36s
  8. 1m 17s
    1. Next steps
      1m 17s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Validating and Processing Forms with JavaScript and PHP.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.