MySQL错误:“字段列表”错误中的未知列

时间:2012-11-06 16:42:29

标签: mysql

嘿伙计我有MySQL的问题,我正在尝试在表中插入数据,但它返回此错误消息

  

致命错误:SQL:SELECT e.idtarea AS'idTarea',e.detalle AS   'detalle',e.precio AS'precio',e.idOrdenReparacion AS   'idOrdenReparacion',e.fecha AS'fecha',concat('Editar',   'Eliminar')AS Opciones FROM Tarea e WHERE e.idtarea like'%%'ORDER   BY e.idtarea;,错误:'字段列表'中的未知列'e.fecha'   第75行/opt/lampp/htdocs/scep/tareas.php

这是我的代码:

    $SQL="

      SELECT 
        e.idtarea AS 'idTarea', 
        e.detalle AS 'detalle', 
        e.precio AS 'precio', 
        e.idOrdenReparacion AS 'idOrdenReparacion', 
        e.fecha AS 'fecha', 
        concat('<a href=\'editarTarea.php?id=',e.idtarea,'\'>Editar</a>&nbsp;','<a href=\'eliminarTarea.php?id=',e.idtarea,'\' onclick=javascript:confirm(\'Eliminar?>\')>Eliminar </a>') AS Opciones 
      FROM Tarea e ".$FILTRAR_POR." 
      ORDER BY e.idtarea;";

      $RESULT = mysql_query($SQL) or trigger_error("SQL: $SQL, Error: " . mysql_error(), E_USER_ERROR); 

数据库中的表Tarea:

CREATE TABLE IF NOT EXISTS `Tarea` (
   `idTarea` int(11) NOT NULL AUTO_INCREMENT,
   `detalle` varchar(45) COLLATE latin1_danish_ci DEFAULT NULL,
   `precio` varchar(45) COLLATE latin1_danish_ci DEFAULT NULL,
   `idOrdenReparacion` int(11) NOT NULL DEFAULT '0',
   `fecha` date DEFAULT NULL,
   PRIMARY KEY (`idTarea`,`idOrdenReparacion`),
   KEY `fk_Tarea_OrdenReparacion1_idx` (`idOrdenReparacion`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_danish_ci AUTO_INCREMENT=2 ;

.....

  ALTER TABLE `Tarea`
  ADD CONSTRAINT `fk_Tarea_OrdenReparacion1` FOREIGN KEY (`idOrdenReparacion`) 
  REFERENCES `OrdenReparacion` (`idOrdenReparacion`) ON DELETE NO ACTION ON UPDATE NO ACTION;

2 个答案:

答案 0 :(得分:1)

您是否已验证该列的先前版本不存在于该列不存在的位置?如果已经存在该表的某个版本,那么您的SQL将不会对表中的列进行更改。

答案 1 :(得分:0)

字段名和别名必须用反引号括起来,而不是像你那样用单引号括起来。更新了查询:

$SQL="SELECT 
    e.idtarea AS `idTarea`, 
    e.detalle AS `detalle`, 
    e.precio AS `precio`, 
    e.idor AS `idOrdenReparacion`, 
    e.fecha AS `fecha`, 
    concat('<a href=\'editarTarea.php?id=',e.idtarea,'\'>Editar</a>&nbsp;','<a href=\'eliminarTarea.php?id=',e.idtarea,'\' onclick=javascript:confirm(\'Eliminar?>\')>Eliminar </a>') AS Opciones 
  FROM Tarea e ".$FILTRAR_POR." 
  ORDER BY e.idtarea;";