Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
我似乎无法弄清楚为什么此查询未运行

if ( $productName && $productDescription && $productPrice ) {
// SQL
// UPDATE `prostud_tristurion`.`products` SET `product_title` = 'ajax test', `product_description` = 'Was certainty remaining engrossed applauded sir how discovery.', `product_price` = '524' WHERE `products`.`product_id` = 10;
try {

    $query = "update products set product_title = :pName, product_description = :pDescription, product_price = :pPrice, where product_id = :pid";
    //prepare query for excecution
    $stmt = $con->prepare($query);

    //bind the parameters
    $stmt->bindParam(':pid', $id);
    $stmt->bindParam(':pName', $productName);
    $stmt->bindParam(':pDescription', $productDescription);
    $stmt->bindParam(':pPrice', $productPrice);
    // echo "$productPrice / $productDescription / $productName / $id\n $stmt";
    var_dump($_POST);
    // Execute the query
    if ($stmt->execute() ) {
        echo "Record was updated.";
    } else {
        die('Unable to update record.');
    }

}catch(PDOException $exception){ //to handle error
    echo "Error: " . $exception->getMessage();
}
}


我得到的只是无法更新记录。

var_dump($_POST);


看起来不错

最佳答案

您在product_price = :pPrice, where处有一个逗号错误

如果您的代码到达die语句,则您已关闭了异常(不建议使用),但是您可以使用$stmt->errorInfo()从数据库中获取错误消息(以记录或回显)

08-25 15:49