Simple Update to MySQL with PHP Object Oriented Programming

I am doing an update into mysql but would like to do this in OOP instead of the procedural method. How can I update with OOP? I am first testing that there is data to update in the input. Check to see if it is empty. Then I take that result and store it into a variable and then I query the database to update the column, I then submit the image file to the correct folder. Below is the code I am working with. I keep getting a blank page. I don’t get any error messages to see where I am going wrong. I have tried a few different modifications but none are working.

    if(!empty($_FILES['logo']) && !empty($_FILES['logoalt'])) { 

        // Testing the connection to MySQL either send message or query MySQL for table creation

        printf("Could not connect to MySQL Database: %s n",$DB->connect_error);
    } else{

        $DB = new mysqli(SERVER,USER,PASSWORD,DATABASE);

            $logo = $_FILES['logo']['name'];
            $logoalt = $_POST['logoalt'];

        if($DB->query("UPDATE HomePageData SET Logo = '$logo', ImgAlt = 'logoalt'")) {

        foreach($_FILES as $file_name => $file_array) {
            if(is_uploaded_file($file_array['tmp_name'])) {
                        or die ("Couldn't move file");  
                            echo "<p>Your data was successfully submitted</p>"; 
            } else {
                printf("Could not load file: %s n",$DB->error);

Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.