Jump to content

[SOLVED] Query Parameter Help


mboucher

Recommended Posts

Hi,

 

I have a query with some parameters, but one of them is not working correctly, it just seems to ignore it completely.  No matter what you enter in it, it returns ALL results.  I've verified the query by running it manually and it should work fine.

 

The parameter that doesn't work is the ItemCode one.

 

<TD class=middle>Item Code:</TD>
				<TD colspan=1 class=middle>
					<input class=input size=15 align=middle type=text name=Itemcode value=$ItemCode>

 

if ($dosearch) {
        if ($GroupCode == "-1")
            $GroupCodeCriteria = "";
        else
            $GroupCodeCriteria = "and i.itmsgrpcod=" . $GroupCode;

	$ItemNameCriteria = "and i.itemname like '%$ItemName%'";
	$ItemCodeCriteria = "and i.ItemCode like '%$ItemCode%'";

	$sql =  "select
			i.ItemCode, i.ItemName, i.OnHand, i.IsCommited, i.OnOrder, g.itmsgrpnam as GroupName
		from 
			OITM i, OITB g
		where i.itmsgrpcod = g.itmsgrpcod
			$GroupCodeCriteria
			$ItemNameCriteria
			$ItemCodeCriteria	";

 

 

Any ideas why it would be ignoring this one?  Both others work fine!

 

Thanks,

Michael

Link to comment
https://forums.phpfreaks.com/topic/149929-solved-query-parameter-help/
Share on other sites

Hi,

 

Where would I put the echo $sql?

There are no errors, it just returns ALL results instead of applying the criteria.

 

Thanks,

 

you are missing {}s from your nested if statements.

 

Braces are not required in simple php blocks.

 

To the op, have you tried echoing $sql? Also, what errors are you getting?

I've done the echo and it appears the input in the itemcode box isn't getting through to the query for some reason...

 

select i.ItemCode, i.ItemName, i.OnHand, i.IsCommited, i.OnOrder, g.itmsgrpnam as GroupName from OITM i, OITB g where i.itmsgrpcod = g.itmsgrpcod and i.itemname like '%%' and i.ItemCode like '%%'

 

you are missing {}s from your nested if statements.

 

Braces are not required in simple php blocks.

 

To the op, have you tried echoing $sql? Also, what errors are you getting?

I've found it, little case sensitivity problem!

 

<input class=input size=15 align=middle type=text name=Itemcode value=$ItemCode>

 

Should have been

<input class=input size=15 align=middle type=text name=ItemCode value=$ItemCode>

 

Thanks for your help!

 

I've done the echo and it appears the input in the itemcode box isn't getting through to the query for some reason...

 

select i.ItemCode, i.ItemName, i.OnHand, i.IsCommited, i.OnOrder, g.itmsgrpnam as GroupName from OITM i, OITB g where i.itmsgrpcod = g.itmsgrpcod and i.itemname like '%%' and i.ItemCode like '%%'

 

you are missing {}s from your nested if statements.

 

Braces are not required in simple php blocks.

 

To the op, have you tried echoing $sql? Also, what errors are you getting?

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.