By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Passing a timestamp to mysql as a variable not working

P: 1
I have queried a mysql database and stored a timestamp that is a primary key for a record in a php variable called $tsdate. I then want to use that php variable when I generate a subsequent query to my mysql database. Unfortunately, this does not seem to work. If I hard code a value of the timestamp into the php sql select statement, it works fine. If I try to replace the hardcoded timestamp value with $tsdate, it fails. Do I need do something special to $tsdate, such as set the variable type, convert to a date, etc.?

Here is an example of the php select statement that works...

$query =mysql_query("SELECT * FROM ColumnA WHERE TimeStamp = \"2010-04-06 23:26:38\"");

Here is an example of the php select statement that does not work...

$tsdate = "2010-04-06 23:26:38"

$query =mysql_query("SELECT * FROM ColumnA WHERE TimeStamp = $tsdate");
Apr 19 '10 #1
Share this Question
Share on Google+
1 Reply


chathura86
100+
P: 227
$query =mysql_query("SELECT * FROM ColumnA WHERE TimeStamp = '$tsdate'");

try this one

Regards
Apr 19 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.