Código PHP:
$seccion = $_POST['seccion'];
$tipo = $_POST['tipo'];
$estatus = $_POST['estatus'];
$pais = $_POST['pais'];
$estado = $_POST['estado'];
$ciudad = $_POST['ciudad'];
$precio1 = $_POST['precio1'];
$precio2 = $_POST['precio2'];
// Escape User Input to help prevent SQL Injection
$seccion = mysql_real_escape_string($seccion);
$tipo = mysql_real_escape_string($tipo);
$estatus = mysql_real_escape_string($estatus);
$pais = mysql_real_escape_string($pais);
$estado = mysql_real_escape_string($estado);
$ciudad = mysql_real_escape_string($ciudad);
$precio1 = mysql_real_escape_string($precio1);
$precio2 = mysql_real_escape_string($precio2);
//build query
if ($seccion!="Seleccione una opcion...")
{
$where_seccion = "seccion LIKE '".$seccion."'";
}
else
{
$where_seccion = "seccion LIKE %";
}
if ($tipo!="Seleccione un Tipo...")
{
$where_tipo = "tipo LIKE '".$tipo."'";
}
else
{
$where_tipo = "tipo LIKE %";
}
if ($estatus!="Seleccione el Status...")
{
$where_estatus = "estatus LIKE '".$estatus."'";
}
else
{
$where_estatus = "estatus LIKE %";
}
if ($pais!="")
{
$where_pais = " pais LIKE '".$pais."' ";
}
else
{
$where_pais = " pais LIKE %";
}
if ($estado!="")
{
$where_estado = " estado LIKE '".$estado."' ";
}
else
{
$where_estado = " estado LIKE %";
}
if ($ciudad!="")
{
$where_ciudad = " ciudad LIKE ".$ciudad."' ";
}
else
{
$where_ciudad = " ciudad LIKE %";
}
if ($nombre!="")
{
$where_nombre = " MATCH(nombre) AGAINST ('".$nombre."') ";
}
else
{
$where_nombre = " nombre LIKE %";
}
if ($precio1!="")
{
$precio1 = $precio1;
}
else
{
$precio1 = 0;
}
if ($precio2!="")
{
$precio2 = $precio2;
}
else
{
$precio2 = 0;
}
if ($precio1!=0 AND $precio2!=0)
{
$where_precio = " costo BETWEEN '".$precio1."' AND '".$precio2."' ";
}
else
{
$where_precio = "costo LIKE %";
}
$where_array = array($where_nombre, $where_seccion, $where_tipo, $where_estatus, $where_pais, $where_estado, $where_ciudad, $where_precio);
$where = implode(" AND ", $where_array);
mysql_select_db($database_century21, $century21);
$query_inmuebles = "SELECT * FROM vivienda WHERE ".$where." ORDER BY id_vivienda ASC";
$query_limit_inmuebles = sprintf("%s LIMIT %d, %d", $query_inmuebles, $startRow_inmuebles, $maxRows_inmuebles);
$inmuebles = mysql_query($query_limit_inmuebles, $century21) or die(mysql_error());
$row_inmuebles = mysql_fetch_assoc($inmuebles);
Código:
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 '% AND seccion LIKE % AND tipo LIKE % AND estatus LIKE % AND pais LIKE % AND es' at line 1