In PHP i want to filter my data by date in my database date column(timestamp type)
up vote
0
down vote
favorite
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.
php mysql
add a comment |
up vote
0
down vote
favorite
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.
php mysql
What is the value of$date
variable ?
– Madhur Bhaiya
Nov 10 at 5:57
This is value of $date= 2018-10-05
– Sonu Kumar Pandit
Nov 10 at 6:00
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
php mysql
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.
php mysql
php mysql
edited Nov 10 at 6:00
asked Nov 10 at 5:48
Sonu Kumar Pandit
85
85
What is the value of$date
variable ?
– Madhur Bhaiya
Nov 10 at 5:57
This is value of $date= 2018-10-05
– Sonu Kumar Pandit
Nov 10 at 6:00
add a comment |
What is the value of$date
variable ?
– Madhur Bhaiya
Nov 10 at 5:57
This is value of $date= 2018-10-05
– Sonu Kumar Pandit
Nov 10 at 6:00
What is the value of
$date
variable ?– Madhur Bhaiya
Nov 10 at 5:57
What is the value of
$date
variable ?– Madhur Bhaiya
Nov 10 at 5:57
This is value of $date= 2018-10-05
– Sonu Kumar Pandit
Nov 10 at 6:00
This is value of $date= 2018-10-05
– Sonu Kumar Pandit
Nov 10 at 6:00
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
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?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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?
add a comment |
up vote
0
down vote
accepted
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?
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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?
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?
answered Nov 10 at 6:03
Madhur Bhaiya
18.8k62236
18.8k62236
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236336%2fin-php-i-want-to-filter-my-data-by-date-in-my-database-date-columntimestamp-typ%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the value of
$date
variable ?– Madhur Bhaiya
Nov 10 at 5:57
This is value of $date= 2018-10-05
– Sonu Kumar Pandit
Nov 10 at 6:00