0

The problem is i want to fetch data on particular date.

This is my form

<form>
<label>Enter the date</label>
    <input type="date" name="date">
  </form>
if(isset($_POST['submit']))
   {
     $date = $_POST['date'];
     $query = "select * from user_date where date ='$date' ";
     }

In database date column(timestamp type) if i write this code this code is not work because i don't pass time.If i pass time this code is work.

1 Answers1

0

Firstly, your code is open to SQL injection related attacks. Please learn to use Prepared Statements

Now, the problem here is that $date value is date only (eg: 2018-11-10), instead of datetime; while your table's date column is of datetime (Timestamp data type).

You need to use Date() function to convert your date column to date only, for checking

$query = "select * from user_date 
          where DATE(date) = '" . $date . "'";

Also, do read: Why is SELECT * considered harmful?

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57