-2

I need to select time from this column.

Picture 1

Column type is datetime.

I have this code now and it's work but not as I want:

$qcreatetime = mysql_query("SELECT create_time FROM ".SQL_HP_DB.".account WHERE id='".$_SESSION['user_id']."'");

while ($rowcreatetime = mysql_fetch_array($qcreatetime))

{$createtime = $rowcreatetime["create_time"];

echo $createtime;}

I got this result with printed echo:

SELECT create_time FROM account_3.account WHERE id='2'

I'm still getting this error:

Picture 2

ReFresh
  • 5
  • 5
  • ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jan 17 '17 at 17:33
  • Thanks for answer, but I'm asking for solving this problem with old mysql because of I'm using old website where is used old mysql. – ReFresh Jan 17 '17 at 17:36
  • `echo "SELECT create_time FROM ".SQL_HP_DB.".account WHERE id='".$_SESSION['user_id']."'";` and check what query printed. update here – Alive to die - Anant Jan 17 '17 at 17:37
  • I got this result with echo: SELECT create_time FROM account_3.account WHERE id='2' – ReFresh Jan 17 '17 at 18:05

2 Answers2

0

This is the right syntax:

"SELECT create_time FROM ".SQL_HP_DB.".account WHERE id=".$_SESSION['user_id'];

You had a single and double quote before and after the session variable. Those were wrong.

Tony T.
  • 94
  • 1
  • 4
  • I already have this right syntax, but I'm still getting error which is mentioned above. @Tony T. – ReFresh Jan 17 '17 at 20:01
0

Problem was in another query so now everything working as I wanted.

ReFresh
  • 5
  • 5