Page 1 of 1

Mysql + php error

Posted: Thu May 29, 2008 4:24 am
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);

Re: Mysql + php error

Posted: Thu May 29, 2008 7:46 am
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

Re: Mysql + php error

Posted: Thu May 29, 2008 2:15 pm
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.

Re: Mysql + php error

Posted: Thu May 29, 2008 2:23 pm
by califdon
I just realized that you have posted the same question twice in a few hours. Please don't do that!