The term you need to find is FIEO. Filter In, Escape Out.
You can easily embarrass yourself if you do not understand this basic principle.
Imagine that PHP is the man in the middle, he gets his left hand and ends on the right.
The user uses your form and fills out the date form, so he should only accept numbers and possibly a dash. e.g. NNNNN-nn-nn. if you get something that doesn't match this, then reject it.
This is an example of filtering.
The following PHP, something with it, allows you to store it in a Mysql database.
What Mysql needs is to be protected from SQL injection, so you use prepared PDO or Mysqli statements to make sure that EVEN IF your filter fails, you cannot allow an attack on your database. This is an example of Escaping, in this case escaping for SQL storage.
Later, PHP gets the data from your db and displays it on the HTML page. Thus, you need to avoid the data for the next medium, HTML (here you can allow XSS attacks).
In your head, you have to separate each of the "protective" PHP functions into one or more of these two families: "Filtering" or "Escaping".
Freetext fields, of course, are more complicated than filtering for a date, but it doesn't matter, stick to the principles and you will be fine.
Hoping this helps http://phpsec.org/projects/guide/