I have a SQL DB where I store information according to dates and times.
The format the SQL stores in is 2013-04-25 15:13:37
The column name is date_time and is Var
My seach PHP is as follow:
<form action="control_lbsresult.php" method="get">
<input type="hidden" name="member_msisdn" value="<?=$query?>"
/>
<input type="text" name="query" />
<br />
<label for="dates"></label>
<input type="date" name="dates" id="dates" />
Start Date<br />
<label for="datee"></label>
<input type="date" name="datee" id="datee" />
End Date<br />
<input type="submit" value="Search" />
</form>
This is the string what it gives in URL
/control_lbsresult.php?member_msisdn=&query=0827910119&dates=2013-04-01&datee=2013-04-
25
This is what i have in my result page:
<?php
$host="localhost"; // Host name
$username="***"; // Mysql username
$password="****"; // Mysql password
$db_name="****"; // Database name
$tbl_name="lbs_"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE date between '" . $dates . "' AND '" . $datee . "'
msisdn='$msisdn'";
It is not filtering between the dates for me and gives me all the results of the MSISDN
I think the problem is in the WHERE string please assist
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.$datesand$dateearen't defined anywhere in your code, and themsisdnpart will cause a syntax error in the SQl as well.