Jump to content

Strange query behaviour


ToonMariner

Recommended Posts

Hi,

 

Posting this in here as the query itself is ok but....

 

OK I have this query....

 

	$qry	=	'
				SELECT
					`t`.*					,
					`s`.`service_name`
				FROM
					`tips`		AS	`t`	,
					`services`	AS	`s`	,
					`customers`	AS	`c`
				WHERE
					`t`.`service_id`	=	`s`.`service_id`
				AND
					`c`.`user_id`		=	' . $_SESSION['user_id'] . '
				AND
					`t`.`tip_date`		<	DATE_ADD(`c`.`startdate`, INTERVAL 90 DAY)
				AND
					`t`.`result` IS NULL
				ORDER BY
					`t`.`tip_date`	DESC
				';
				echo $qry;
	$qry	=	mysql_query($qry) or die(mysql_error());

 

If I run the query directly in phpmyadmin (with session['user_id'] as a value) it returns the results as expected.

 

Running the self same query through php I get this

 

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 13

 

I am running this locally - php 4.4.4 mysql 4.1.21.

 

Can anyone suggest why this error is reported when the query is fine in phpmyadmin???

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/53863-strange-query-behaviour/
Share on other sites

You mean $_SESSION['user_id']?

 

No that is the correct way to reference an string index... if you would use $_SESSION[user_id] then may I suggest you change - its all about code style, consitency and support.  In future the php engine may refuse to recognize the non-quote method...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.