I have the following input code that I want the user to key in his year of birth. My lecturer has asked me to use textbox for the user to put in the year of birth, date and
Cast the variable to an integer:
$year = (int) $_POST['year'];
The type attribute is actually irrelevant to how PHP handles the value. Try casting it as int:
$month = $_POST['month'];
$day = $_POST['day'];
$year = (int) $_POST['year'];
if(checkdate($month,$day,$year))
{
//$dob is a valid date
echo "<p>Date of birth:$day $month $year</p>";
}
else
{
//$dob is a not valid date
$day = null;
$month = null;
$year = null;
echo "<p><b><font color=red>Please enter a <mark>valid</mark> date of birth!</font></b></p>";
}