I have an html file, plstats_search.html that includes a form. The menu list in this form allows a user to select a range that the 'pop' field is part of.
The form calls up plstats_search.php to do the query and display the table with two columns, Library Name and Population Served.
I am able to pull up the table headings, but no data. I didn't really know what I was doing when I specified the <SELECT> items. I just put in a range and used single and double quotes.
My other question was about the query. I had named the select menu "searchtype" and in the query used a LIKE to say:
".$searchtype ." LIKE '%".$searchtype."%'
I suspect that my problem is with the query or with the selection syntax. Can someone shed some light on this?
Form within plstats_search.html
<form method="post" action="plstats_search.php">
<tr>
<td> Population served:
<select name="searchtype">
<option value="pop >'1' and pop < '2000'">1-1,999
<option value="pop >'2000' and pop < '5000'">2,000-4,999</option>
</select>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type=submit value="Submit">
</div>
</td>
</tr>
</form>
Calls up plstats_search.php
<html>
<head>
<title>Public Library Statistics</title>
</head>
<body>
<center><h2>Public Library Statistics</h1></center>
<?php
@ $db = mysql_connect("wherever.com", "user", "pass");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
$searchtype = $POST["searchtype"];
$searchterm = $POST["searchterm"];
$searchterm = trim(preg_replace("/[A-Za-z0-9 -. ]/","",$searchterm));
mysql_select_db("libdev");
$query = "select * from pldir where ".$searchtype ." LIKE '%".$searchtype."%' ORDER by pop";
$result = mysql_query($query);
// start results formatting
echo "<CENTER><TABLE BORDER=1>";
echo "<TR><TH>Library</TH><TH>Population Served</TH></TR>";
// format results by row
while ($row = mysql_fetch_array($result))
{
$LIBNAME = $row["name"];
$FSCE = $row["fsce"];
$DEPT = $row["dept"];
$PHONE = $row["deptphone"];
$POP = $row["pop"];
echo "<TR><TD><B>$LIBNAME</A></B></TD><TD><B>$POP</B></TD></TR>";
}
echo "</p>";
echo "</TABLE></CENTER>";
// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);
?>
</body>
</html>