Problem with Image Upload Script

Good day house. I was assisted with the code below some few years back on this platform when I had conditional update issue with my query and it worked fine in case the logged in user decides not to upload any image. It didn’t throw up error messages. The code is below:

        $sql = "UPDATE service SET patronize = :patronize".((!empty($uploadname)) ? ", filename = :filename" : "")."".((!empty($uploadtype)) ? ", mimetype = :mimetype" : "")."".((!empty($uploaddata)) ? ", filedata = :filedata" : "")."".((!empty($uploadsize)) ? ", filesize = :filesize" : "")." WHERE username = :username";
        $s = $conn->prepare($sql);
        $s->bindValue(':patronize', $patronize);
        if(!empty($uploadname)) { $s->bindValue(':filename',$uploadname); }
        if(!empty($uploadtype)) { $s->bindValue(':mimetype',$uploadtype); }
        if(!empty($uploaddata)) { $s->bindValue(':filedata',base64_encode($uploaddata)); }
        if(!empty($uploadsize)) { $s->bindValue(':mimetype',$uploadsize); }
        $s->bindValue(':username', $username);
        catch (PDOException $e)
        $error[] = "There was an error while updating your information, Please try again later";


The above code works well. Now, i want to adapt the same code for INSERT statement and can’t just figure out how to do it. The truth is that I don’t even know how the UPDATE statement above works. I just copied and use. I will appreciate if the UPDATE statement can be explained and INSERT statement example provided. Thanks in advance.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.