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? Quote 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 Quote 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" Quote 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. Quote 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] Quote Link to comment https://forums.phpfreaks.com/topic/15931-mysql-error/#findComment-65449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.