0

The code:

$selecteddate = $_POST['Releasedate'];
$selectedplatform =$_POST['Platform'];
$selectedstyle = $_POST['style'];
$query="SELECT * FROM $table WHERE date = '$selecteddate'AND Style = '$selectedstyle'AND Platform = '$selectedplatform'";

Ok, the code works if someone picks something for all 3 of the items, so all of the code works, but if someone leaves one of the $selected items blank I have it returning a *, which doesn't mean what I thought it would mean. So what should I have it return so that if they do not choose an option I want it to just ignore that part of the WHERE condition?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Virtualbase
0
$selecteddate = $_POST['Releasedate'];
$selectedplatform =$_POST['Platform'];
$selectedstyle = $_POST['style'];

$whereclause = "";
if ($selecteddate!="*") $whereclause.= " AND date='$selecteddate' ";
if ($selectedplatform!="*") $whereclause.= " AND Platform='$selectedplatform' ";
if ($selectedstyle!="*") $whereclause.= " AND Style='$selectedstyle' ";

if (strlen($whereclause) > 0) $whereclause = " WHERE ".substr($whereclause,4);

$query="SELECT * FROM $table $whereclause";

If you change your form to return "" instead of "*" on blank inputs, just remove the * in lines 6,7,8

0

You can also make javascript validation along with the Server Side Validation on the form in order to post/get the correct values.

I hope the above solution did help.

Thanks,

Mike

Edited by Ezzaral: Snipped "fake sig" link. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.

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.