Can someone see if they can help figure out where my issue is with this code???
Background:
This is my display page, it pulls info from a search form and also inserts that info into a table. I then have it pulling search criteria from a table and displaying results, when a user clicks on a certain link. So I have my display page set up so that it pulls from a search form or from a table based on where the user is coming from.
These are the 2 options
1. search (gets search criteria from search form)
2. search2 (pulls search criteria from table directly)
I have both working when the user is looking for genderPref == 3 however when the user looks for genderPref 1 or 2 then I get the following error when I am pulling the info from the table directly
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 '' at line 12
I have attached my code but here is a snippet as well - this is where I am getting my error on both else's
// GETTING ERRORS IN THESE 2 else's
// gender = 1 or 2 and zip is empty
else{
if(empty($zip_code)) {
$where = "WHERE user.bd_year <= $year1 AND user.bd_year >= $year2 AND user.gender = $genderPref AND user.genderPref = $gender ";
if (!empty($smoke))
{
$where .= " AND about_me.smoking = $smoke";
}
if (!empty($religion))
{
$where .= " AND bkgd.relg = $religion";
}
if (!empty($heightMin))
{
$where .= " AND appearance.height >= $heightMin";
}
if (!empty($heightMax))
{
$where .= " AND appearance.height <= $heightMax";
}
if (!empty($hairColor))
{
$where .= " AND appearance.hair_color = $hairColor";
}
if (!empty($eyeColor))
{
$where .= " AND appearance.eye_color = $eyeColor";
}
$result = mysql_query("SELECT user.userID, user.gender, user.genderPref, user.city, user.state, photos.photo_1,
CURDATE(), (YEAR(CURDATE())-YEAR(birth_date)) - (RIGHT(CURDATE(),5)<RIGHT(birth_date,5)) AS age
FROM user
LEFT JOIN photos
ON user.userID = photos.userID
LEFT JOIN about_me
ON user.userID = about_me.userID
LEFT JOIN bkgd
ON user.userID = bkgd.userID
LEFT JOIN appearance
ON user.userID = appearance.userID
$where")or die(mysql_error());
} // end of empty($zip_code)
// gender = 1 or 2 and zip is NOT empty
else{
$z = new zipcode_class;
$zips = $z->get_zips_in_range($zip_code, $miles, _ZIPS_SORT_BY_DISTANCE_ASC, true);
if ($zips == false) {
echo ""; }
else {
$zips_in_range = implode(',', array_keys($zips) );
$where = "WHERE zip IN (". $zips_in_range .") AND user.bd_year <= $year1 AND user.bd_year >= $year2 AND user.gender = $genderPref AND user.genderPref = $gender ";
if (!empty($smoke))
{
$where .= " AND about_me.smoking = $smoke";
}
if (!empty($religion))
{
$where .= " AND bkgd.relg = $religion";
}
if (!empty($heightMin))
{
$where .= " AND appearance.height >= $heightMin";
}
if (!empty($heightMax))
{
$where .= " AND appearance.height <= $heightMax";
}
if (!empty($hairColor))
{
$where .= " AND appearance.hair_color = $hairColor";
}
if (!empty($eyeColor))
{
$where .= " AND appearance.eye_color = $eyeColor";
}
$result = mysql_query("SELECT user.userID, user.gender, user.genderPref, user.city, user.state, photos.photo_1,
CURDATE(), (YEAR(CURDATE())-YEAR(birth_date)) - (RIGHT(CURDATE(),5)<RIGHT(birth_date,5)) AS age
FROM user
LEFT JOIN photos
ON user.userID = photos.userID
LEFT JOIN about_me
ON user.userID = about_me.userID
LEFT JOIN bkgd
ON user.userID = bkgd.userID
LEFT JOIN appearance
ON user.userID = appearance.userID
$where")or die(mysql_error());
} // end of valid search
} // end of search