Archive for December 21st, 2005

Variable Casting

I thought I'd do a few small tutorials on data validation. Pretty much all websites now require some sort of user input, be it in the form of a newsletter or user registration, or a shopping cart. Its important that this data that is inputted is validated, else you'll find the wrong sort of data is inputted - either due to a malicious user, or a stupid one!

A lot of people get into PHP as its rather easy to code, but they overlook the most simple of input validation routines to ensure that the data coming from the end user matches what they expect. The golden rule of writing a PHP application is to never trust the user input, whether its come from a form via POST, the URL via GET or even a cookie.

Continue Reading 3 comments December 21st, 2005

Getting totals in MySQL

At work recently, I had to grab the sum of totals from multiple rows meeting certain conditions in a mysql table. Rather than get each total and add them in PHP in a loop, I decided to get MySQL to do all the legwork for me:

SELECT sum(amount)
FROM table
WHERE id = '$id'
AND condition = '1'
GROUP BY id;

That should return you a summation of the amount columns for all rows matched in the the WHERE statemtents.

1 comment December 21st, 2005


Calendar

December 2005
M T W T F S S
« Nov   Jan »
 1234
567891011
12131415161718
19202122232425
262728293031  

Posts by Month

Posts by Category