0

Hopefully I don't have to put all my code in. I have 3 separate pages of php set up. I want a user to be able to go to my website and search a bunch of criteria to find a good school for himself. There are checkboxes, radio buttons, text boxes, etc. Here's the problem code:

$query = "SELECT * FROM post_sec_all_stats WHERE DURA_SCH=$dura_sch AND CTRL_SCH=$ctrl_sch AND POPU_AREA_SCH$popu_area_sch ORDER BY UNITID";
	$result = mysql_query($query) or die("Error processing <strong>query</strong>. ".mysql_error());

And here's the form that I'm using:

<form method="post" action="school_list.php">
<input type="checkbox" value=">=11 && <=13" name="popu_area_sch"> Urban<br />
<input type="checkbox" value=">=21 && <=23" name="popu_area_sch"> Suburban<br />
<input type="checkbox" value=">=31 && <=33" name="popu_area_sch"> Town<br />
<input type="checkbox" value=">=41 && <=43" name="popu_area_sch"> Rural<br />
<br />
</form>

When I check "suburban", for example, and submit, I get this error :
Error processing query. 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 '<=23 ORDER BY UNITID' at line 1

Anybody got any suggestions? (By the way, if you can't tell, I'm super new at this. Started this whole php kick a few days ago, and am seriously addicted.) Thanks!

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by jdgieschen
0

echo your query
think gona look like

....  AND POPU_AREA_SCH>=11 && <=13 ORDER BY UNITID

this is not valid sql

0

Exactly. I see that it doesn't work to query like this. I had thought it was proper syntax, but as you say, it must not be. This is what I get when I echo the query:

SELECT * FROM post_sec_all_stats WHERE DURA_SCH=1 AND CTRL_SCH=1 AND POPU_AREA_SCH>=21 && <=23 ORDER BY UNITID

So I know that it's wrong. Now, is there any way to fix it to accomplish the same goal? Thanks.

0

I thought

POPU_AREA_SCH>=1 && <=10

meant it would search that field in the database for any number between 1 and 10.

Then I probably can't use

STATE_SCH='AL||FL||MS||AZ||TX'

to search the database for any of these states either, huh? Am I just mistaken in the operators, or...?

Thanks.

0

for your STATE_SCH look at mysql instr

for POPU_AREA_SCH do some thinge like

switch ($popu_area_sch) {
    case 'Urban':
       $query .= "POPU_AREA_SCH>=11 AND POPU_AREA_SCH <=11";
        break;
    case 'Suburban':
        $query .= "POPU_AREA_SCH>=21 AND POPU_AREA_SCH <=23";
        break;
    ...
    ...
    }
$query .="ORDER BY UNITID";

You als have to change the value of your <input>

<input type="checkbox" value="Urban" name="popu_area_sch"> Urban<br />

Edited by pzuurveen: n/a

0

Great! I now see. I've got to repeat the POPU_AREA_SCH part. That worked well. Don't quite understand the STATE_SCH part, but I can work around that. I've got so many questions, and I love learning this stuff. Thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.