Query doesn't go through with AND syntax included

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
EverToDesign
Forum Newbie
Posts: 10
Joined: Sat Oct 11, 2003 9:38 am

Query doesn't go through with AND syntax included

Post by EverToDesign »

Hey, thanks for the read. Basically here it is. When I keep it as

$query = "SELECT asReportID, ADtransnum FROM $reports_table WHERE asReportID = '$controlnumber'
$order_by_str $sort_order_str $limit_str";


The search works fine

however there are multiple Agents so it needs to be more specific and grab only where the report iD is equal to $controlnumber and one other field the value of which is stored in session

$query = "SELECT asReportID, ADtransnum FROM $reports_table WHERE RAgency2 = '$_SESSION[id]' AND asReportID = '$controlnumber'
$order_by_str $sort_order_str $limit_str";

now I echoed out the $_SESSION[id] so I know its there and comes up as the appropriate value. Any ideas?

Edit> There was a typo in my last post. This is what the code looks like as above only ONE AND is there it still does not work though.
Last edited by EverToDesign on Sat Jul 10, 2004 1:01 pm, edited 1 time in total.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Theres too many AND's

Code: Select all

$query = "SELECT asReportID, ADtransnum FROM $reports_table WHERE RAgency2 = '$_SESSIONїid]' AND asReportID = '$controlnumber' $order_by_str $sort_order_str $limit_str";
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$query = "SELECT asReportID, ADtransnum FROM $reports_table WHERE AND RAgency2 = '$_SESSION[id]' AND asReportID = '$controlnumber'
$order_by_str $sort_order_str $limit_str";
Not sure if all that was a typo or not..but the syntax is..
SELECT ... FROM ... WHERE ... AND ... AND ..ORDER BY
you have
SELECT ... FROM ... WHERE AND ... AND ... ORDER BY

*beaten to it*
Post Reply