See how you get on with this ...
//$con = mysql_connect("localhost", "pinehead", "") or die(mysql_error());
//$db = mysql_select_db("pinehead", $con) or die(mysql_error());
if(isset($_POST['uname'])) {
$sql = "SELECT * FROM users WHERE user='".$_POST['uname']."'";
if(!isset($_POST['agemin'])) {
$sql .= " AND age > 18";
}
if(!isset($_POST['agemax'])) {
$sql .= " AND age < 80";
}
if(isset($_POST['location'])) {
$sql .= " AND location LIKE '%.".$_POST['location']."%'";
}
if(!isset($_POST['sex']) || $_POST['sex'] == "any") {
$sql .= " AND (sex='male' OR sex='female')";
}
$sql .= " ORDER BY create_date";
} else {
$sql = "Error: uname must be set!";
}
echo $sql;
//$result = mysql_query($sql,$con);
//while ($row = mysql_fetch_array($result)) {
// ... other stuff here
//}
1) I assumed that the whole things depends on $_POST['uname'] being passed to the page ... everything else optional.
2) Newer versions of PHP don't allow using $uname for $_POST['uname'] unless you've specifically configured that way. It's much easier to debug, anyway.
3) Never embed PHP variables in strings ...
Don't do: "My name is $name";
Do: "My name is ".$name;
... it's faster and easier to debug.
Come back if you need more help with the logic.