doushouhe7072 2018-01-07 13:27
浏览 75
已采纳

PHP PDO执行错误42000

I am getting a 42000 PDO error, I know this has to do with MySQL reserved words and I have put all my column names in backticks. However, this has not solved my problem. I am using Xampp on Windows 10, I am wondering if it could be an Apache or MySQL error and not a PHP syntax error?

class ItemList {

private $pdo;

public function add() {
  $stmt = $this->pdo->prepare("INSERT INTO `item` (`ID`, `userID`, `name`, `description`, `price`, `link`, `image`) 
                                           VALUES (NULL, :userID, :name, :description, :price, :link, :image)");

  $stmt->execute(array(':userID' => $_SESSION['userID'], 
                        ':name' => $_REQUEST["name"],
                        ':name' => $_REQUEST["name"],
                        ':description' => $_REQUEST["description"],
                        ':price' => $_REQUEST["price"],
                        ':link' => $_REQUEST["link"],
                        ':image' => $_REQUEST["image"]
                       )); 
    }
}

I know this may be a stupid easy answer and that I may just be stuck and I know there are some similar questions out there already. But any help would be greatly appreciated, thanks in advance.

  • 写回答

2条回答 默认 最新

  • donglei3370 2018-01-27 02:51
    关注
        $stmt = $this->pdo->prepare("INSERT INTO item 
        ( userID, `name`, description, price, link, image) 
        VALUES ( :userID, :name, :description, :price, :link, :image)");
    

    name is a reserved word in MySQL you only need it in backticks, also NULL values are not necessary for your statements.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么