Sync between app and online databases

So I want to Sync my app databases with my databases online, And it is not working fine:

So here I send my data to the server

        var stmt = "SELECT * FROM card WHERE Productsync = 0 ";
        //console.log(stmt);
        $cordovaSQLite.execute(db, stmt).then(function(res) { //console.log(res)
            if(res.rows.length > 0) {
                var link = 'http://deelist.comli.com/heziikhvs2336658999854/546864687fzefgq/486468/416841568463hgdseijhkbsncyproooo.php';
                for (var i = 0; i < res.rows.length; i++){
                    console.log(res.rows.item(i));
                    console.log(res.rows.item(i).ProductName);
                    console.log(res.rows.item(i).ProductBarcode);
                    console.log(res.rows.item(i).ProductPakking);
                    console.log(res.rows.item(i).ProductPresent);
                    console.log(res.rows.item(i).ProductMinimuim);
                    console.log(res.rows.item(i).FotoUrl);
                    console.log(res.rows.item(i).DBid);

                    var targetPath = "android_asset/www/" + res.rows.item(i).FotoUrl;

                    // File name only
                    var filename = targetPath.split("/").pop();

                   var options = {
                        fileKey: "file",
                        fileName: filename,
                        chunkedMode: false,
                        mimeType: "text/plain",
                        params : {'directory':'/', 'fileName':filename, 
                                    'ProductName':res.rows.item(i).ProductName,
                                    'ProductBarcode':res.rows.item(i).ProductBarcode,
                                    'ProductPakking':res.rows.item(i).ProductPakking,
                                    'ProductPresent':res.rows.item(i).ProductPresent,
                                    'ProductMinimuim':res.rows.item(i).ProductMinimuim,
                                    'DBid':res.rows.item(i).DBid,
                                }
                    };
                        //console.log(email)
                    $cordovaFileTransfer.upload(link, targetPath, options).then(function (result) {
                          console.log("SUCCESS: " + JSON.stringify(result.response));
                          /*var stmt = "UPDATE orderScans SET order_Action= ? WHERE order_Action = ?";
                          $cordovaSQLite.execute(db, stmt, ["SEND", "TOSEND"]).then(function(res){
                            //$window.location.reload(true)
                          })*/
                    }, function (err) {
                        console.log("ERROR: " + JSON.stringify(err));
                    }, function (progress) {
                        // PROGRESS HANDLING GOES HERE
                    });
                  }

                 }


        });

And my php script looks like this

header(‘Access-Control-Allow-Origin: *’);

$ProductName = ($_POST[‘ProductName’]);
$ProductBarcode = ($_POST[‘ProductBarcode’]);
$ProductPakking = ($_POST[‘ProductPakking’]);
$ProductPresent = ($_POST[‘ProductPresent’]);
$ProductMinimuim = ($_POST[‘ProductMinimuim’]);
$DBid = ($_POST[‘DBid’]);

$location = ($_POST[‘directory’]);
$myfile = ($_POST[‘fileName’]);
$uploadfilename = $_FILES[‘file’][‘tmp_name’];

//check if removed to …

if(move_uploaded_file($uploadfilename, $location.’/’.$myfile)){
//echo ‘File successfully uploaded!’+ $uploadfilename, $location.’/’.$myfile;

//insert
$myfileName = pathinfo($myfile, PATHINFO_FILENAME);

if (is_executable($myfile)) {
    echo $myfile.' is executable';
}else{
        $query ="SELECT ProductName FROM `card` WHERE
                `ProductName` = '" . $ProductName . "' AND
                `ProductBarcode` = '" . $ProductBarcode . "' AND
                `ProductPakking` = '" . $ProductPakking . "' AND
                `ProductPresent` = '" . $ProductPresent . "' AND
                `ProductMinimuim` = '" . $ProductMinimuim . "' AND
                `FotoUrl` = '" . $FotoUrl . "' AND
                `DBid` = '" . $DBid ."'";                    
        $result_set = mysqli_query($connection,$query);
        if (mysqli_num_rows($result_set) == 0){
                echo "niet gevonden";
            $query ="INSERT INTO `card` (ProductName,ProductBarcode,ProductPakking,ProductPresent,ProductMinimuim,FotoUrl,DBid)
            VALUES( '" . $ProductName . "' ,
                    '" . $ProductBarcode . "' ,
                    '" . $ProductPakking . "' ,
                    '" . $ProductPresent . "' ,
                    '" . $ProductMinimuim . "' ,
                    '" . $FotoUrl . "' ,
                    '" . $DBid ."')";
            $result = mysqli_query($connection,$query);
        }else{
            echo "update";
            $query = "UPDATE `card`
            SET  `ProductName` = '" . $ProductName . "' ,
                `ProductBarcode` = '" . $ProductBarcode . "' ,
                `ProductPakking` = '" . $ProductPakking . "' ,
                `ProductPresent` = '" . $ProductPresent . "' ,
                `ProductMinimuim` = '" . $ProductMinimuim . "' ,
                `FotoUrl` = '" . $FotoUrl . "' ,
                `DBid` = '" . $DBid ."'
            WHERE `ProductBarcode` = '" . $ProductBarcode . "' AND `DBid` = '" . $DBid ."'";
            $fines = mysqli_query($connection,$query);
        }

The problem is that my php file inserts the same data multiple times. I have this problem for already 3 days, I’ve tried to solve it with different kind of methods but none of them worked out, eventually. Can someone please tell me how I can solve this problem? I’d like to send my data from my local DB to my php file on my server. My php file should insert my data when non existing, but if so, it should update. Thank you in advance!

its fixed, so nvm :grinning: