First off, I am glad its working for you.

It is a little tid bit of code I use for quite a few things, and having the error checking for the variable values this way (1 to 5) is quite a bit more secure than the text method.
If you wanted to, you could keep the category out of the link (URL), and have a added "hidden" input statement in your FORM statment.
Code: Select all
<input type="hidden" name="category"> (something like that...)
Secondly, you could add another drop down list into your HTML page (either rite next to your other drop down, or rite underneath it for only design purpostes) for the first part of your query. Basically, take everything that was posted in above, but make it like this:
Code: Select all
<!--this is your first select area now modified-->
<table summary="" border="0" bgcolor="blue" width="41%">
<tr>
<td valign="top">
<form action="<? echo($PHP_SELF); method="post" ?>
<select name="0" value="category">
<option value="" value="">Select Joke Topic:</option>
<option value="" value="">----------------</option>
<option value="1">All</option>
<option value="2">General</option>
<option value="3">Microsoft</option>
<option value="4">Programming</option>
<option value="5">Helpline</option>
</select>
</form>
</td>
<!--end first select area-->
<!--Start-just a spacer/add a picture-->
<td bgcolor="f1f1f1" width="20%">
</td>
<!--end spacer-->
<!--start second search by form-->
<td width="33%" valign="top">
<form name="sorted">
<select name="0" value="by">
<option value="" value="">Select By:</option>
<option value="" value="">------------</option>
<option value="1">All</option>
<option value="2">Author</option>
<option value="3">Title</option>
<option value="4">Joke</option>
</select> </form>
</td>
</tr>
</table>
<table summary="" border="0" bgcolor="00362" width="41%">
<tr>
<td align="center">
<input type="submit" value="Select A Joke!" name="submit">
</td>
</tr>
</table>
Now, you can see with the second form, I have added a variable "sorted". This will be similar to category of your old code. So, we need to do the same things as we did for category in your .php script. with the sorted area.
Code: Select all
if (empty($sorted)) {
print "Please select a valid choice";// make sure they are chosing from your list
exit;
}
if ($sorted>0 && $sorted<="4") { //make sure only the selections are used
if ($sorted=="1") {
$DB_Sort=="*";
}
if ($sorted=="2") {
$DB_Sort=="author";
}
if ($sorted=="3") {
$DB_Sort=="title";
}
if ($sorted=="4") {
$DB_Sort=="joke";
}
}
Than again, the SQL will have to be modified now for the new variables:
Code: Select all
$sql="select '$DB_Sort' from jokes WHERE category='$DB_request' ";
Be sure to read the next post first.....
Try this, and than get back to me.
