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
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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.