user2762353
user2762353

Reputation:

Is this sql query even acceptable?

another dumb question to brighten your day. I have this MySql query and, yes, it doesn't shown any result. What's wrong here? Is it the AND or the ORDERBY? hmmm...

 SELECT * FROM statisticData WHERE SYear LIKE '$SYr' AND accessDate BETWEEN '$startDate' AND '$endDate' ORDER BY accessDate DESC

Oh, this is what comes before the query:

   $SYr = $_POST['SYr'];
   $startDate = date("m-d-Y", strtotime($_POST['Date1']));
   $endDate   = date("m-d-Y", strtotime($_POST['Date2']));

the needed inputs

Upvotes: 0

Views: 53

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324720

Dates in MySQL must be in Y-m-d format. m-d-Y is not acceptable and will not return any rows.

xkcd

Also:

xkcd

Escape your inputs. Its okay for the date ones because you're handling them already and the output is a PHP-generated date. But $SYr is currently unsafe.

Upvotes: 2

Related Questions