gpt4 book ai didi

在每行中插入图像的 PHP 代码

转载 作者:行者123 更新时间:2023-11-29 14:47:54 25 4
gpt4 key购买 nike

我在下面的编码中需要帮助,现在每次我插入新的槽表单时它都会更新图像,我需要它应该在每一行中更新/插入图像而不是更新相同的图像,请帮助..代码如下

<?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;
}
?>

最佳答案

您的查询意味着数据库中的所有行都会将该图像作为 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')

关于在每行中插入图像的 PHP 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6482788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com