digitalgod Posted July 28, 2006 Share Posted July 28, 2006 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? Link to comment https://forums.phpfreaks.com/topic/15931-mysql-error/ Share on other sites More sharing options...
kenrbnsn Posted July 28, 2006 Share Posted July 28, 2006 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 Link to comment https://forums.phpfreaks.com/topic/15931-mysql-error/#findComment-65445 Share on other sites More sharing options...
Barand Posted July 28, 2006 Share Posted July 28, 2006 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" Link to comment https://forums.phpfreaks.com/topic/15931-mysql-error/#findComment-65446 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 [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 whatif you are trying to pass a variable to check the namelike a variable as what you are selectingit 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. Link to comment https://forums.phpfreaks.com/topic/15931-mysql-error/#findComment-65447 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/15931-mysql-error/#findComment-65449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.