且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP图像替换?

更新时间:2023-02-19 13:54:18

  $ image_name =; 
if(!empty($ _ FILES)){
$ image_name = $ _FILES ['image'] ['tmp_name'];


$ sql =UPDATE table SET var1 ='value1',var2 ='value2';
if($ image_name!=)
$ sql。=,image_name ='。$ image_name。';
$ sql。=WHERE id_entry = 5;


I'm having a brain dead moment... If someone could talk this through with me and make suggestions that'd be great.

I'm importing a URL from a database, eg www.mysite.com/images/image1.jpg set as variable newimage1

This is loaded from the DB and placed on the page.

As this is an edit page, the user can upload a new image.

If the user doesn't upload a new image, but saves the page anyway, the variable newimage1 is not set, it clears the existing image url from the database because the variable is set to "".

What's the best way to do this? An if statement, that checks if newimage1 is blank and removes it from the update to the database?

Sorry for this simple question!

$image_name = "";
if(!empty($_FILES)){
    $image_name = $_FILES['image']['tmp_name'];
}

$sql = "UPDATE table SET var1 = 'value1', var2='value2'";
if($image_name != "")
    $sql .= ", image_name = '".$image_name."'";
$sql .= " WHERE id_entry = 5";