我在编程方面有点新意。我希望有人可以帮我解决我的问题。我试图更新我的数据,但这个错误不断出现,我不知道该怎么做。这是我的代码
function updatePromo($name, $imageLocation, $dateRelease, $date){
if(!isset($this->db))
return new Exception("Failed to update promo");
$sql = "UPDATE `promo` SET `name` = :name,
`image_location` = :image_location,
`date_release` = :date_release,
`date` = :date WHERE `id` = :id";
return $this->db->db_insert($sql, array(
'name'=>$name,
'image_location'=>$imageLocation,
'date_release'=>$dateRelease,
'date'=>$date
));
这是更新数据的代码
$db = new PROMO_DAO();
$name = $_POST['updateName'];
$dateRelease = strtotime($_POST['updateDate'])*1000;
$date = $_POST['updateDate'];
$temp_dir = getTempUploadDir();
// mysql inserting a new row
$result = $db->updatePromo($name, $temp_dir, $dateRelease, $date);
// check if row inserted or not
if ($result > 0) {
$newId = $db->getLastInsertedId($name);
$temp_target_file = $temp_dir . basename($_FILES["updateImage"]['name']);
$imageFileType = pathinfo($temp_target_file,PATHINFO_EXTENSION);
$newfilename = 'promo_' . $newId . '.' . $imageFileType;
uploadImage($_FILES["updateImage"], $newfilename);
$db->updateImageLocation($name, '/images/' . $newfilename);
$response["status"] = 1;
$response["message"] = "Promo updated successfully.";
} else {
throw new RuntimeException("Failed to update Promo: " . $name);
}
答案 0 :(得分:0)
您缺少一个参数和冒号,将它们添加到插入调用中,如下所示
$sql = "UPDATE `promo` SET `name` = :name,
`image_location` = :image_location,
`date_release` = :date_release,
`date` = :date WHERE `id` = :id";
return $this->db->db_insert($sql, array(
':name'=>$name,
':image_location'=>$imageLocation,
':date_release'=>$dateRelease,
':date'=>$date,
':id'=>$id
));
答案 1 :(得分:0)
在数组中,您没有在密钥中添加:
,也没有在查询的:id
子句中使用WHERE
参数。
希望这能帮助您解决问题