我在下面的编码中需要帮助,现在它每次插入新的槽形式时都会更新图像,我需要它应该更新/插入每行中的图像而不更新相同的图像,请帮助..代码如下
<?PHP
if(isset($_POST['add_value'])){
$sql ="INSERT INTO tb_special_offer (offer_price, offer_title, offer_desc, offer_link) VALUES ('"
.addslashes($_REQUEST['offer_price'])."', '"
.addslashes($_REQUEST['offer_title'])."', '"
.addslashes($_REQUEST['offer_desc'])."', '"
.addslashes($_REQUEST[offer_link])."')";
$qry = mysql_query($sql) or die (mysql_error());
//Image
if($_FILES['offer_img']['name']){
$uploaded_image = $_FILES['offer_img']['name'];
$imgpath = "userfiles/specialoffer/";
if(file_exists($imgpath.$uploaded_image)) unlink($imgpath.$uploaded_image);
if(!move_uploaded_file($_FILES['offer_img']['tmp_name'], $imgpath.$uploaded_image)){
$errMsg= "UPLOAD ERROR..!!!".$_FILES['offer_img']['name'];
}
else {
$sql = "update tb_special_offer set offer_img='$uploaded_image' ";
$qry = mysql_query($sql) or die (mysql_error());
}
}
header("Location: specialoffer?msg=Special Offer Added Successfully!");
exit;
}
?>
答案 0 :(得分:1)
您的查询意味着数据库中的所有行都将该图像作为offer_img
列的值。更新意味着:更新一行。
如果要更新特定行,而不是每行,请执行以下操作:
update tb_special_offer set offer_img='$uploaded_image' where id=xxxx
但我怀疑你想使用INSERT查询。由于您没有提供任何更多信息,我无法为您编写,但它应该很容易。只需阅读the manual,但归结为
INSERT into tb_special_offer (offer_img) VALUES ('$uploaded_image')