Mysql + php error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
piyush
Forum Newbie
Posts: 2
Joined: Thu May 29, 2008 4:21 am

Mysql + php error

Post by piyush »

I got following 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 '' at line 1

$latestid = "SELECT id,fr_id,max(frd_date) FROM emp WHERE user_id ='$uid' and status='0' GROUP BY id DESC Limit 1";
$latestresult = mysql_query($latestid) or die(mysql_error());
$num1 = mysql_fetch_array($latestresult);
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Re: Mysql + php error

Post by Jaxolotl »

Query seems to be ok, I create the DB structure and make the query with no error messages.

Code: Select all

 
CREATE TABLE `emp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fr_id` int(11) NOT NULL DEFAULT '0',
  `frd_date` date NOT NULL DEFAULT '0000-00-00',
  `user_id` int(11) NOT NULL DEFAULT '0',
  `status` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY  (`id`),
  KEY `fr_id` (`fr_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
SELECT id,fr_id,max(frd_date) FROM emp WHERE user_id =''1'' and status=''0'' GROUP BY id DESC Limit 1


Wich MySQL version are you using? Limit max() or Group may not be available for that version
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Mysql + php error

Post by califdon »

It seems that MySQL isn't reading even the first word of your query string, since the error says: near ": -- meaning that it hasn't even read "SELECT". Try echoing the contents of your $latestid variable, right before you try to query the database.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Mysql + php error

Post by califdon »

I just realized that you have posted the same question twice in a few hours. Please don't do that!
Post Reply