MySQL中的插入失败错误

时间:2010-04-19 20:26:11

标签: php mysql

while($row=mysql_fetch_array($result2)){    
        //return $row['ProjectID'];
        $sql="INSERT INTO `tycodashboard` (ProjectID,DesignationID,ReqcompID,IntOrgID,FinishedTimeID,ProjectStatusID,PhaseID
                ) VALUES('{$row['ProjectID']}','$pm,'$req','$initiating,'$initiating','$ftime,'$ProjectStatus,'$Phase)";
        $result=mysql_query($sql);
        if(!$result){
            if(mysql_errno() == ER_DUP_ENTRY){
                throw new Exception("INSERT FAILED.\n\nThe database already contains a Project with the Project Name \"$ldesc\", please pick another.");
            }else{
                throw new Exception("INSERT FAILED.\n\n".mysql_error());
            }
        }
        }//exits

    INSERT FAILED.

    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 '3','2,'2','2,'2,'3)' at line 2

1 个答案:

答案 0 :(得分:7)

您可以从错误消息中看到错过一大堆引号:

'3','2,'2','2,'2,'3

尝试在缺少引号的地方添加引号,看看是否有帮助:

$sql="INSERT INTO `tycodashboard` (ProjectID,DesignationID,ReqcompID,IntOrgID,FinishedTimeID,ProjectStatusID,PhaseID
      ) VALUES ('{$row['ProjectID']}','$pm','$req','$initiating','$initiating','$ftime','$ProjectStatus','$Phase')";