PHP PDO Not Updating Table and Producing No Errors

隐身守侯 提交于 2019-12-11 01:49:34

问题


I'm trying to update a single element in one of my tables using a PDO prepared statement, and for some reason it's not working. I'm using try-and-catch and I'm receiving no errors from the system. I've also echoed both of my bound parameters, and they are both registering in the system, so I don't know why it's not going through. I've used a query very similar to this in another script and everything was fine.

if($_POST['check_request'] == "Yes"){
    $check_amnt = $_POST['check_amnt'];
    try {
        $STH = $DBH->prepare('UPDATE accounts SET check = :check_amnt WHERE accnt = :user');
        $STH->bindParam(':check_amnt', $check_amnt);
        $STH->bindParam(':user', $ulog);
        $STH->execute();
    }
    catch(PDOException $e) {  
        echo "Check Input Error: " .$e->getMessage(). "</br>";
    }
}

回答1:


Did you set the exception mode for PDO with:

$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Update: check is mysql reserved words, you need to escape it.

$STH = $DBH->prepare('UPDATE accounts SET `check` = :check_amnt WHERE accnt = :user');


来源:https://stackoverflow.com/questions/12190452/php-pdo-not-updating-table-and-producing-no-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!