Jump to content

Query in PHP script not working, but is used to!


woodsmic

Recommended Posts

I wrote a script sometime ago, which pulls records from a mysql database.

 

I use a html form which passes the variables to the script, which can find records by order number, email address or between certain dates.

 

Since my host has upgraded PHP on his server, the query I used to pull the records between certain dates has stopped working.  Below is the query used in my script:

 

$datefrom is passed from a form.

$dateto is passed froma form.

datetime is the field in my database.

 

$sql = "SELECT * FROM orders WHERE DATE_FORMAT(datetime,'%Y%m%d') >= DATE_FORMAT('$datefrom','%Y%m%d') and DATE_FORMAT(datetime,'%Y%m%d') <= DATE_FORMAT('$dateto','%Y%m%d') ORDER BY datetime";

 

I think it is something to do with DATE_FORMAT..  As I say it used to work, nothing has changed apart from the php version on the server.

 

Any ideas?  I have tried for hours, which has acheived nothing except giving me a headache!

 

Thanks in advance guys.

 

 

Mike.

 

 

 

 

Just to add:

 

$datefrom and $dateto are in the format :

 

$datefrom = date("Ymd", $datefromform);

 

datetime comes from the database in the format "2007-01-30 20:20:20"

 

I need both to be in the same format so the query can work, but i dont know how.

 

Cheers!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.