Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/02/2013, 05:02
diegesis
 
Fecha de Ingreso: julio-2010
Mensajes: 29
Antigüedad: 13 años, 10 meses
Puntos: 0
Respuesta: Error SQL syntaxis al realizar una búsqueda

Este es el aviso:

Error al Ejecutar la Consulta: 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 'ANULADO'' order by 'clientes.provincia,usuarios.nombre,acciones.fcrea cion' lim' at line 1

Haga donde haga la consulta en el formulario (si pongo más variables el aviso de error es más largo oviamente) me dice que es error de sintaxis. Os paso parte del archivo donde puede estar el error:

Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. //  echo $_POST["anadir"];
  16.   $filtros='';
  17.  
  18.   $querys='';
  19.   if(isset($_GET['estado'])) {
  20.     if ( $_GET['estado']=='ANULADO'){
  21.     $filtros.="accion_alumno.estado='ANULADO' AND ";
  22.     $querys.="estado=ANULADO&";
  23.     }elseif($_GET['estado']=='IMPAGADO'){
  24.     $filtros.="accion_alumno.estado<>'ANULADO' AND accion_alumno.IdAccion in (select det_fra_emp.IdAccion from facturas_empresas,det_fra_emp where facturas_empresas.IdFactura=det_fra_emp.IdFactura and (facturas_empresas.estado='PTE. PAGO' or facturas_empresas.estado LIKE 'IMPAGADO%')) AND ";
  25.     $querys.="estado=IMPAGADO&";
  26. }elseif($_GET['estado']=='PAGADO'){
  27.     $filtros.="accion_alumno.estado<>'ANULADO' AND accion_alumno.IdAccion in (select det_fra_emp.IdAccion from facturas_empresas,det_fra_emp where facturas_empresas.IdFactura=det_fra_emp.IdFactura and facturas_empresas.estado='PAGADO' ) AND ";
  28.     $querys.="estado=PAGADO&";
  29.  
  30.     }elseif($_GET['estado']==''){
  31.     $filtros.="accion_alumno.estado<>'ANULADO' AND ";
  32.     $querys.="estado=&";
  33.     }
  34. }
  35.   foreach($_GET as $indice => $valor) {
  36.   if ( $indice!='pag' && $indice!='orden' && $indice!='estado'){
  37.     if ($valor!='') {
  38.     $querys.="$indice=$valor&";
  39.     if ($indice=='fcreacion2'){
  40.     $valor=guardafecha($valor);
  41.         $filtros.="acciones.fcreacion between '$valor' and  '".sumaDia($valor,6)."' AND "; 
  42.         }else{
  43.         if ($indice=='ffin2'){
  44.         $valor=guardafecha($valor);
  45.         $filtros.="acciones.ffin between '$valor' and  '".sumaDia($valor,6)."' AND ";
  46.         }else{ 
  47.     if ($indice=='fcreacion'){
  48.  
  49.         $filtros.="month(acciones.$indice)='$valor' AND "; 
  50.         }else{
  51.         if ($indice=='anofcreacion'){
  52.  
  53.         $filtros.="year(acciones.fcreacion)='$valor' AND ";
  54.         }else{
  55.         if ($indice=='ffin'){
  56.        
  57.         $filtros.="month(acciones.$indice)='$valor' AND ";
  58.         }else{
  59.         if ($indice=='anoffin'){
  60.        
  61.         $filtros.="year(acciones.ffin)='$valor' AND ";
  62.         }else{     
  63.         if ($indice=='IdUsuario'){
  64.         $filtros.="(clientes.$indice='$valor' or usuarios.IdParent='$valor') and ";
  65.         }else{
  66.         if ($indice=='provincia'){
  67.         $filtros.="clientes.$indice='$valor' AND ";
  68.        
  69.         }elseif($indice=='tiporegalo'){
  70.         $filtros.="accion_alumno.$indice='$valor' AND ";
  71.         }elseif($indice=='IdArea'){
  72.             if($valor=='ELEARNING'){
  73.             $filtros.=" (cursos.IdArea=14 or cursos.IdArea=15 or cursos.IdArea=16) and ";
  74.             }elseif($valor=='A DISTANCIA'){
  75.             $filtros.=" (cursos.IdArea<>14 and cursos.IdArea<>15 and  cursos.IdArea<>16 and  cursos.IdArea<>12) and ";
  76.             }else{
  77.            
  78.             $filtros.="cursos.$indice='$valor' AND ";
  79.             }
  80.        
  81.         }else{
  82.            
  83.         $filtros.="cursos.$indice like '%$valor%' AND ";
  84.         }
  85.         }
  86.         }
  87.         }
  88.         }  
  89.         }
  90.         }
  91.         }              
  92.    
  93.     }
  94.     }
  95.   }
  96. ?>
  97.  
  98. <table width='905' border='0' cellpadding='3'> <tr class='filaimencabezados'>
  99.   <td width="3%">&nbsp;</td>
  100.     <td width="6%">Provincia</td>
  101.     <td width="11%">Delegado</td>
  102.     <td width="8%">Comercial</td>
  103.   <td width="7%">Cliente</td>
  104.   <td width='5%'>Precio</td>
  105.   <td width='9%'>Fecha Venta</td>    <td width="16%">Denominación</td>
  106.   <td width="9%">Compromiso</td>
  107.   <td width="9%">Test</td>
  108.   <td colspan="2">Estado</td>
  109. </tr>
  110. <?php
  111.    
  112.    
  113.      if ($filtros!='') {
  114.   if (!isset($_GET['pag'])){
  115.    $pag = 1;
  116.    }else{
  117.    $pag=$_GET['pag'];
  118.    }
  119.      if (!isset($_GET['orden']) or empty($_GET['orden'])){
  120.    $orden = "clientes.provincia,usuarios.nombre,acciones.fcreacion";
  121.    }else{
  122.    $orden=$_GET['orden'];
  123.    }
  124.     $filtros=substr($filtros,0,strlen($filtros)-5); //se quita ultimo -AND-
  125.    
  126.    
  127.  
  128.     $result = mysql_query("SELECT COUNT(acciones.IdAccion)as total ,sum(cursos.precio) as ventas from accion_alumno,acciones, cursos,alumnos,clientes,usuarios where clientes.IdUsuario=usuarios.IdUsuario and clientes.IdCliente=alumnos.IdCliente and accion_alumno.IdAlumno=alumnos.IdAlumno and accion_alumno.IdAccion=acciones.IdAccion and acciones.IdCurso=cursos.IdCurso   and '$filtros'", $conexion);
  129. $row = @mysql_fetch_array($result);
  130. $total=$row['total'];
  131. $ventasA=$row['ventas'];
  132. $tampag = 100;
  133.  
  134.  
  135. $reg1 = ($pag-1) * $tampag;
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.     $consulta="select  cursos.*, alumnos.nombre, alumnos.ap1, alumnos.ap2,clientes.entidad,accion_alumno.*,usuarios.nombre as com, clientes.provincia, acciones.*, accion_alumno.estado as estado1,accion_alumno.regalo as regalo2,usuarios.ap1 as com1 ,usuarios.IdParent,usuarios.IdPerfil from accion_alumno,acciones, cursos,alumnos,clientes,usuarios where clientes.IdUsuario=usuarios.IdUsuario and clientes.IdCliente=alumnos.IdCliente and accion_alumno.IdAlumno=alumnos.IdAlumno and accion_alumno.IdAccion=acciones.IdAccion and acciones.IdCurso=cursos.IdCurso  and '$filtros'  order by '$orden'  limit $reg1,$tampag";
  143.     $result=mysql_query($consulta) or die ("Error al Ejecutar la Consulta: ".mysql_error());