Looking to dive into the wonderful world of PHP & MySQL? The following tutorials should help you get started.

[divider3 text=”The Basics”]

Echo();

Chances are you’re familiar with the Hello World exercise by now. It’s the starting point for learning almost any programming language. PHP is no different. So let’s dive right into it. How do we display things using PHP?

Escaping Characters & Variable Expansion

Escaping characters is rather basic, however understanding how it functions together with various variables is essential to an error-free PHP script.

Variables – The Basics

If you have ever looked through any programming language – or still remember those algebra classes when you learned what 3+x=5 means. A variable stores something inside of it so that you can recall it later on in your scripting. So let’s take a look at creating variables and storing information in them through PHP.

Variables – Understanding Global, Local, and Static Variable Scope

There’s much more to variables than just setting and using them. PHP places variables into three different scopes: the global, local, and static scope. Properly understanding and using these different scopes can make or break your PHP application.

Understanding PHP Constants

A constant within PHP is essentially an identifier for a simple value, and unlike a variable, the value of a constant cannot be changed after it is declared. By default a constant is case-sensitive; and most people tend to give constant identifiers uppercase names.

Understanding IF/ELSE/ELSEIF Statements

he majority of the time your PHP application or script will vary depending on different conditions. These conditions can be set via the script itself, or from user interaction – regardless your PHP script needs a way to handle these different situations. This is where conditional statements in PHP are introduced.

The PHP Switch Conditional Statement

The switch statement essentially acts as an alternative the if…elseif…else statement when the condition for each statement is checking the same variable.

The Ternary Operator

PHP has plenty of different operators, the majority of them being either unary or binary operators. A unary operator, such as !, performs its operations on just one single value. A binary operator, such as =, is used to perform an operation on two operads. So following the naming logic you’ve probably already figured out that a PHP ternary operator performs a single operation on three different values.

How Functions Work

A function is merely a block of code that can be defined once and then reused throughout various other parts of your script/program. Throughout this tutorial we will take a look at exactly how PHP functions are written.

String Manipulation – Using SUBSTR & STRLEN PHP Functions

PHP has a wide array of functions already available for you to use to work with various strings. So let’s say that we have a variable holding a user’s telephone number and we’re asking our user to input the last 4 digits of their phone number to verify themselves. To do this we’re going to use the help of the substr (substring) function.

String Manipulation – Using STRPOS and STR_REPLACE PHP Functions

Let’s say we are storing the users full name within our database in a single column in the following format firstName-lastName. However on our frontend we want to be able to echo out the first and last name separately. This is where the strpos function comes into play.

Making Life Easier with While Loops

The WHILE loop is one of the most useful commands in PHP. It is also quite easy to set up and use – granted it might look a bit complicated. First off however let’s figure out just what the hell a WHILE loop is – and what we need it for. A WHILE loop will, as the name suggests, execute a piece of code while a certain condition is met. So – what’s the point? WHILE loops make repetitive tasks much less annoying than they usually are.

FOR and FOREACH Loops

Much like WHILE loops FOR and FOREACH loops are meant to enable the repeated execution of a section of code. However, unlike while statements, for and foreach have features built into them to update the sentinel value for every repetition.

Include Another File Within Your Script

The ability to include additional files within your PHP script is crucial for proper managing & organizing your code. For example, if you are writing an eCommerce shopping cart script the function that gets real-time UPS shipping quotes is 24KB worth of XML processing goodness, but you use it only when someone chooses UPS as a shipping option. Why not store it in ups_ship_quotes.php and call it only when necessary? Let’s learn how.

Sending Email with PHP

Mail is extremely easy to send from PHP, unlike using scripting languages which require special setup (like CGI). There is actually just one command, mail() for sending mail. In this tutorial we will discuss how to use PHP’s mail() function.

The Basics Of PHP Classes and Objects

As you learned in previous tutorials functions provide a way for you to divide your program’s tasks into separate, smaller tasks. Classes and objects are somewhat similar in helping you to organize your program. They are used to create collections of related variables and functions, which can be used to more accurately represent real-life situations.

[divider3 text=”Getting Started With MySQL Databases”]

Connecting to a MySQL Database

None of our previous PHP tutorials have dealt with a database yet, and that is for the sole reason that not everyone has access to a database, however for those who do this tutorial will teach you the basics on how you can connect to your database.

Connecting to a MySQL Database Using PHP Data Objects

With the release of PHP 5.5.0 the mysql_* functions have become deprecated and as such connecting to a MySQL database with PHP 5.5 and up will require the use of either PHP Data Objects (PDO) or an individual MySQL driver (MySQLi). Throughout this tutorial we will focus on utilizing PDO to connect, access, and disconnect from a MySQL database.

Issuing Statements to a MySQL Database Using PHP Data Objects

This tutorial expands upon our previous PHP Data Objects tutorial, which discusses how to connect to a MySQL database, and showcases how to communicate with that MySQL database once you are connected.

[divider3 text=”Real World Examples”]

File Upload via PHP/MySQL

As per the request of Spaculus I have decided to put together a tutorial discussing how to upload an image to your server, and store the information about that uploaded image into your MySQL database.

File Upload via PHP/MySQL – Error Checking

This tutorial aims to expand upon the basic file upload functionality that was discussed previously and introduces various error checking features for file size, and file types, etc.

Basic PHP Template System

PHP has many different template solutions, and the beauty of them all is how simple it makes maintaining and changing your website. Back in the day when everything was handled with static HTML files – if you needed to add a new link to your main menu – you found yourself editing dozens if not hundreds of different files.  With PHP you can break up your website into several sections, includes if you will. So the menu code can all be within 1 single file, which you include on other pages.

Display Page Loading Time

Have you ever noticed that lots of websites feature some text towards the very bottom of a page saying “Page took x.xxx seconds to load”? It’s a pretty simple thing to make and gives your site something that we all love … stats!

Display A Gravatar Via PHP

Learn how to use the Gravatar API to display a users Gravatar image, give it a custom size, and if a Gravatar image doesn’t exist for that user display a default avatar of our choice.

Auto Generation of New Prospects in eLEAD CRM via ADF XML

ADF stands for Auto Data Format which is the standard data delivery format for the automotive industry. Using ADF XML leads and customer details can easily be imported/exported across a wide array of platforms and dealerships. This tutorial covers v1.0 of the ADF XML specifications to see how to convert a simple HTML form to interact with eLEAD CRM thanks to PHP.

How to Validate Form Data with PHP

Proper form validation can help ensure you stay safe from SQL injection attacks! As such it’s important to ;earn how to properly validate any type of form data with the help of PHP.

How To Populate A DIV via an HTML SelectBox, PDO, and jQuery

This PHP tutorial will introduce you to a quiet common combination, jQuery & PHP. These two programming languages often work together to handle various dynamic content. Here we will dynamically update a specific area of a webpage depending on what we select via a form dropdown.

Published by Michael Boguslavskiy

Michael Boguslavskiy is a full-stack developer & online presence consultant based out of New York City. He's been offering freelance marketing & development services for over a decade. He currently manages Rapid Purple - and online webmaster resources center; and Media Explode - a full service marketing agency.

Join the Conversation

1 Comment

  1. Very clear and helpful for beginners. Great job you did here php tutorials that covers all the basics of php with examples and helps to learn html for Beginners Online.

Leave a comment

Your email address will not be published. Required fields are marked *