Looking to dive into the wonderful world of PHP & MySQL? The following tutorials should help you get started.
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 is rather basic, however understanding how it functions together with various variables is essential to an error-free PHP script.
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.
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.
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.
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 switch statement essentially acts as an alternative the if…elseif…else statement when the condition for each statement is checking the same variable.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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!
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.
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.
Read More »