Building Classes

In this post we build a class to process recipes in a recipe app.  We will explore how to initialise a class, define properties, create objects and call methods. So what do we want our class to do? Fetch recipes Add recipes Update recipes Remove recipes Let's

Storing & retrieving data with Arrays

Arrays are like lists. In programming terms arrays are the same as variables that store data but the crucial difference is they store elements of data that is normally related in some way. Think of them a bit like a draw - take a kitchen

How to connect to a MySQL Database using PHP

There are two ways to connect to a MySQL database using PHP. There is the procedural method and the OOP method. Both are valid but arguably the OOP method, using PHP’s Database Object (PDO) is a more robust method in terms of error

Ternary Operator (:?)

The ternary operator is a shorthand for if/else. Why bother with the ternary operator? Wherever possible it makes sense to optimize your code. In so doing you reduce the load on the server and write less code (never a bad thing!). By optimizing your scripts as much

PHP Magic Quotes

What are Magic quotes? Magic Quotes is a function that is designed to help escape potentially Malformed data inputs in PHP forms. The problem with Magic Quotes is that the function escapes not only suspicious characters but inverted commas and speech marks as well.

PHP Sessions

Sessions are designed to exist within a current user session. They also run purely on the server side and unlike Cookies nothing is pushed to the browser’s cache (client side). So, what are sessions good for? Imagine you have a shopping cart site that requires a login

The anatomy of a PHP cookie

What is a cookie? A cookie is a text file that is sent from the server and is stored in the browser’s cache. Cookies can enhance the usability of your application by either setting predefined variables within the application or gathering information entered by the user