Jump to content


Photo

mysql error


  • Please log in to reply
4 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 28 July 2006 - 09:21 PM

hey guys,

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

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

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

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


any ideas?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 July 2006 - 09:26 PM

Strings in MySQL need to be delimitied by quotes. Try:
<?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());
?>

Ken

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 28 July 2006 - 09:29 PM

Put single quotes round the session value

"SELECT * FROM " . $prefix . "users WHERE created >= '".$_SESSION['last_login']."' ORDER BY id"
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 09:29 PM

mysql_query("SELECT * FROM " . $prefix . "users WHERE created >= ".$_SESSION['last_login']." ORDER BY id") or die(query_error());
$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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 28 July 2006 - 09:31 PM

<?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());
?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users