繁体   English   中英

用于在每行中插入图像的php代码

[英]Php Code for Inserting images in each row

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

<?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查询。 由于您没有提供更多信息,因此我无法为您编写信息,但这应该很容易。 只是阅读手册 ,但归结为类似

INSERT into tb_special_offer (offer_img) VALUES ('$uploaded_image')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM