ok so I need to search a database for names of people that were born between two dates, the website asks the user to input a date in this format dd/mm/yyyy so i need to manipulate is so that it will work in my sql search. What I did was this
$date_1 = $_GET["date_1"];
$date_2 = $_GET["date_2"];
function reorderDate($date) { //30/11/1970
$firstbrk = strpos($date, '/');
$day = substr($date, 0, $firstbrk);
$month = substr($date, $firstbrk + 1, -5);
$year = substr($date, strlen($date) - 4);
$corrDate = $year.
"-".$day.
"-".$month;
return $corrDate;
}
echo $Cdate_1 = reorderDate($date_1);
echo $Cdate_2 = reorderDate($date_2);
$tablename = 'Cyclist';
$sql = "SELECT name, dob FROM Cyclist WHERE dob > ' . $Cdate_1 . ' AND dob < ' . $Cdate_2 . ';";
$res = & $db - > query($sql);
if (PEAR::isError($res)) {
die($res - > getMessage());
}
echo "<br>";
echo $findings_numb = $res - > numRows();
while ($row = $res - > fetchRow()) {
echo $row[0].
"
";
}
I am not finding anything in the database, but if I use this line to search instead I find many results why?
$sql = "SELECT name, dob FROM Cyclist WHERE dob > '1970-30-11' AND dob < '1990-30-11';";
</div>