I have a database that has a row called shapes and contains entries with either rectangles, squares and circles. I currently have the following code to get only get the shape that the user requests. (Currently it’s either rectangles and circles, squares and circles or only circles). For some reason, it’s not working and throwing a database error. Can anyone help me?
“MEMBER_FROM” is the column they’re under
$where = "";
if($context['no_sq'] == 1 && $context['no_rec'] == 0) {
$where .= " WHERE MEMBER_FROM != 'Square'";
} else if($context['no_sq'] == 1 && $context['no_rec'] == 0) {
$where .= " WHERE MEMBER_FROM != 'Rectangle'";
} else if($context['no_sq'] == 1 && $context['no_rec'] == 1) {
$where .= " WHERE MEMBER_FROM != 'Square' AND MEMBER_FROM != 'Rectangle'";
}
$request = mysql_query("SELECT ID_SHAPES FROM {$db_prefix}shapes WHERE ID_MEMBER = {$memID}{$where}", __FILE__, __LINE__);
You can’t say WHERE twice. Use AND…
UPDATE:
Based on your statement that your shapes are exclusion checkboxes it would make more sense to name those boxes in an array then build your query based on a loop. Otherwise this code could be very hard to maintain…
then in PHP
… obviously escaping that $exclude var, but for simplicity let’s assume you are escaping user input.