0

Hi I want to search the items present in the table users. The code I wrote is

$fromdate = date("Y-m-d H:i:s", strtotime($_POST['fromdate'])); $todate = date("Y-m-d H:i:s", strtotime($_POST['todate'])); $s="SELECT * FROM logs WHERE dt BETWEEN $fromdate AND $todate ORDER BY dt DESC "; $x = mysql_query($s); 

But the output is not showing. Please someone help me.

2
  • try with $s="select * from logs where dt between '$fromdate' and '$todate' order by dt desc ";// you forget quotes in your query Commented Apr 8, 2015 at 9:14
  • 4
    You need to put $fromdate and $todate in quotes. Avoid writing php variables directly in sql statement. Commented Apr 8, 2015 at 9:14

2 Answers 2

1

Need to apply quotes around '$fromdate' and '$todate' as

$s="SELECT * FROM logs WHERE dt BETWEEN '$fromdate' AND '$todate' ORDER BY dt DESC "; 
Sign up to request clarification or add additional context in comments.

Comments

0
$fromdate = strtotime($_POST['fromdate']); $todate = strtotime($_POST['todate']); $query="SELECT * FROM logs WHERE UNIX_TIMESTAMP(dt) BETWEEN $fromdate AND $todate ORDER BY dt DESC "; 

1 Comment

While this may answer the question it’s always a good idea to put some text in your answer to explain what you're doing. Read how to write a good answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.