As a web developer, you need to be on the lookout for many different types of security issues, and SQL injection is a major one. SQL injection is a technique where malicious MySQL statements are inserted into your SQL. Learn more about what SQL injections are and how they work in this online training video.
My SQL has a very definite syntax, and we've been learning that. A few times in the last movies, we even broke that syntax on purpose just so we could see what the error messages looked like. Once we start constructing SQL queries using dynamic data from variables, then we also have to be careful that the values we use don't break MySQL syntax. For example, the single quote is an important part of an insert statement because it goes around all string values. So for example if we had insert into subjects, we have the column names values and then about widget corp and that goes in single quotes. Now let's imagine that we've written that so that it takes a dynamic value. We did this just a few movies ago.
Where we're going to now insert menu name and menu name is going to be a variable. Well what if our menu name is Today's Widget Trivia? What if that's the string that we want to drop in there? Insert into subjects, menu name position visible, the values Today's Widget Trivia. Do you see the problem with that? Let me highlight it for you. We're closing our single quotes without meaning to. The result of this is that MySQL thinks that the string that we're sending is "today," and that's it, and we have broken the rest of it. Everything else after that will be seen as being garbage and we'll get an error back.
Now, this is an innocent example, but sometimes the values that come in are not ours, nor are they even from well-meaning admins of the site. URL strings, form data and cookies are often coming in from the public at large. And therefore they're completely out of our control as developers. And not everyone who comes to our website has our best interests in mind. If we use those values exactly as they come in we could be in for a world of hurt. Let me show you an example. Let's say that we have menu name and it's equal to that single quote at the beginning followed by some SQL that someone else would like us to run. Followed by another single quote at the end which they may have to modify it slightly so that it doesn't raise an error and it actually does execute. But you can see the result here.
They're basically taking what was a simple insert statement and turning it into dropping our entire table of subjects. And they can do other things, too. They can actually have it export all of our users and their passwords, things like that, that we don't want them to do. This process is called SQL injection. The user sends a carefully crafted URL string, or a form field value, and it injects their SQL into ours. SQL injection is the single easiest way for someone to hack your website and steal your data. Sql_injection is the single biggest problem that you need to be guarding against as a web developer.
There are lots of things that you need to watch out for when you are developing for the web. And lots of security issues you should be concerned about. But sql_injection is the big one. Now if you stop and think about it. Breaking the syntax of SQL is similar to how we saw that we could break the syntax of a URL or HTML earlier on. And the solution, here, is going to be the same as it was for both of those. We need to escape the string. That is, to transform it so that any problem characters that are in it are rendered harmless. So, let's learn how to do that. Let's learn the ways in PHP that we can escape strings to make them safe for putting into queries that we're going to send to SQL.
- What is PHP?
- Installing and configuring PHP and MySQL
- Exploring data types
- Controlling code with logical expressions and loops
- Using PHP's built-in functions
- Writing custom functions
- Building dynamic webpages
- Working with forms and form data
- Using cookies and sessions to store data
- Connecting to MySQL with PHP
- Creating and editing database records
- Building a content management system
- Adding user authentication
Skill Level Beginner
Q: This course was revised on 6/4/2013. What changed?
A: The old version of this course was 6 years old and it was time for a complete revision, using PHP 5.4. (The tutorials will work with any version of PHP and covers any differences you might encounter). The author has also added updated installation instructions for Mac OS X Mountain Lion and Windows 8. The topics and end project are the same, but the code is slightly different. It also addresses frequently asked questions from the previous version.
Q: This course was updated on 5/20/2015. What changed?
A: We added one movie called "Changing the document root in Yosemite," which helps the Mac installation run more smoothly.
PHP with MySQL Beyond the Basicswith Kevin Skoglund10h 26m Intermediate
Ajax with PHP: Add Dynamic Content to Websiteswith Kevin Skoglund3h 37m Intermediate
1. PHP Overview
2. Mac Installation
3. Windows Installation
4. First Steps
5. Exploring Data Types
6. Control Structures: Logical Expressions
7. Control Structures: Loops
8. User-Defined Functions
10. Building Web Pages with PHP
11. Working with Forms and Form Data
12. Working with Cookies and Sessions
13. MySQL Basics
14. Using PHP to Access MySQL
15. Building a Content Management System (CMS)
16. Using Site Navigation to Choose Content
17. Application CRUD
18. Building the Public Area
19. Regulating Page Access
Next steps2m 4s
- Mark as unwatched
- Mark all as unwatched
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.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.