Jump to content

Archived

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

digitalgod

mysql error

Recommended Posts

hey guys,

trying to figure out why this query is giving me an error..

[code]
mysql_query("SELECT * FROM " . $prefix . "users WHERE created >= ".$_SESSION['last_login']." ORDER BY id") or die(query_error());
[/code]

"created" is formatted in DATETIME and so is $_SESSION['last_login'] but I keep getting this error

[quote]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '16:46:09 ORDER BY id' at line 1[/quote]

any ideas?

Share this post


Link to post
Share on other sites
Strings in MySQL need to be delimitied by quotes. Try:
[code]<?php
$q = "SELECT * FROM " . $prefix . "users WHERE created >= '".$_SESSION['last_login']."' ORDER BY id");
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>[/code]

Ken

Share this post


Link to post
Share on other sites
Put single quotes round the session value

"SELECT * FROM " . $prefix . "users WHERE created >= [color=red]'[/color]".$_SESSION['last_login']."[color=red]'[/color] ORDER BY id"

Share this post


Link to post
Share on other sites
[code]mysql_query("SELECT * FROM " . $prefix . "users WHERE created >= ".$_SESSION['last_login']." ORDER BY id") or die(query_error());[/code]
$select  = "SELECT * FROM users, WHERE
atleast explain what the $prefix is, and for what
if you are trying to pass a variable to check the name
like a variable as what you are selecting
it should be
"SELECT * FROM '$prefix', users WHERE created >= '$_SESSION[last_login]';";  The only thing you need for the session is $_SESSION[last_login] surrounded by single quotes.

Share this post


Link to post
Share on other sites
[code]<?php
$q = "SELECT * FROM '$prefix', users WHERE created >= '$_SESSION[last_login]' ORDER BY id";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>[/code]

Share this post


Link to post
Share on other sites

×

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.