Elyor Elyor - 2 months ago 8x
PHP Question

using value of html input type month in mysql where clause

I have a HTML input type month, like

<input name="month" type="month" />


$bywherecls="WHERE DATE_FORMAT(fromdate, '%Y %m') = '".$_GET['month']."'";

value of
is like

what is wrong with the query above?


Your format should be %Y-%m, not %y %m.
With your current code you are checking WHERE 'YYYY MM' = '2016-08', which will never return any results.

$bywherecls="WHERE DATE_FORMAT(fromdate, '%Y-%m') = '".$_GET['month']."'";

And you should never send data directly from the user to the database. use some escape function or use prepared statements.