I want to UPDATE a row in a table or INSERT it if it doesn't exist?
I have already read solution from this link. How do I UPDATE a row in a table or INSERT it if it doesn't exist?
So, i used replace but it did not work. It only added new row into the table but did not update anything.

<?php
define('ROOTPATH', __DIR__);
$output = [];
$output['result'] = [];
$output['image_path'] = [];
$applicationName = (isset($_POST) && array_key_exists('applicationName', $_POST)) ? $_POST['applicationName'] : 'applicationName';
if (empty($applicationName)) {
    $output['result'][] = 'missing application name';
}
else if (is_array($_FILES) && array_key_exists('image', $_FILES) && array_key_exists('logo', $_FILES))
{
    $upload_dir  = '/upload_dir/';
    $upload_path = ROOTPATH . $upload_dir;
    $applicationName = $_POST['applicationName'];
    $sql_field_list  = ['applicationName'];
    $sql_value_list  = [$applicationName];
    foreach ( $_FILES as $key => $upload) {
        if($key != 'image' && $key != 'logo')
        {
            $output['result'][] = $key . ' is invalid image';
        }
        else
        {
            if ($upload['error'] == UPLOAD_ERR_OK &&
                preg_match('#^image\/(png|jpg|jpeg|gif)$#', strtolower($upload['type'])) && //ensure mime-type is image
                preg_match('#.(png|jpg|jpeg|gif)$#', strtolower($upload['name'])) ) //ensure name ends in trusted extension
            {
                $parts     = explode('/', $upload['tmp_name']);
                $tmpName   = array_pop($parts);
                $fieldname = ($key == 'image') ? 'bgBNPage' : 'logo';
                $filename  = $applicationName . '_' . $fieldname . '.' . pathinfo($upload["name"], PATHINFO_EXTENSION);
                if (move_uploaded_file($upload["tmp_name"], $upload_path . $filename))
                {
                    $sql_field_list[] = $fieldname;
                    $sql_value_list[] = $upload_dir . $filename;
                    $output['image_path'][$key] = $upload_dir . $filename;
                }
                else
                {
                    $output['result'][] = $key . ' upload fail';
                }
            }
            else
            {
                $output['result'][] = $key . ' error while upload';
            }
        }
    }
    //after upload complete insert pic data into database
    $con = mysqli_connect("localhost", "root", "root", "museum");
    if (!$con) {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $fields = implode(', ', $sql_field_list);
    $values = implode("', '", $sql_value_list);
    $sql = "REPLACE INTO general (" . $fields . ") VALUES ('" . $values . "');";
    if (!mysqli_query($con, $sql)) {
        die('Error: ' . mysqli_error($con));
    }
    mysqli_close($con);
} else {
    $output['result'][] = 'no file selected';
}
    header('Content-type: application/json');
    echo json_encode($output);
    echo json_encode('finish');
?>
Can i use
if(logo or bgBNPage is enpty)
{
insert into database
}
else{
Update database
}
please tell me the correct syntax.

 
     
    