<?
header('Access-Control-Allow-Origin: *');

//var_dump(json_decode(file_get_contents("php://input")));
$postData = json_decode(file_get_contents("php://input"));

$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

//{"jenama":"jenama1","model":"model1","produk":"idproduk1","sku":"sku1","remark":"remark1","type":"TOYS","attrib4":"BAT","attrib5":"1v","attrib6":"1kg","attrib7":"1saiz","prod_year":"2017","waranti":"tiada1","insuran":"tiada1","base1":"data:image/png;base64","base2":""}
//LPAD(COUNT(*)+1,3,'0'), 
$query = "UPDATE items SET 
            photo = '" .$postData->base1. "', 
            jenama = '" .$postData->jenama. "', 
            model = '" .$postData->model. "', 
            attrib3 = '" .$postData->attrib3. "', 
            attrib4 = '" .$postData->attrib4. "', 
            attrib5 = '" .$postData->attrib5. "', 
            attrib6 = '" .$postData->attrib6. "', 
            attrib7 = '" .$postData->attrib7. "', 
            produk = '" .$postData->produk. "', 
            sku = '" .$postData->sku. "', 
            remark = '" .$postData->remark. "', 
            type = '" .$postData->type. "', 
            waranti = '" .$postData->waranti. "', 
            insuran = '" .$postData->insuran. "', 
            prod_year = " .$postData->prod_year. ", 
            manu = '" .$postData->manu. "' WHERE nfc = '" .$postData->nfc. "' ";

if ($mysqli->query($query) === true) {
    echo "Success: Record updated. [".$query."]";
    http_response_code(200);
} else {
    echo "Error: Process failed - " . $mysqli->error . "[".$query."]";
    http_response_code(401);
}

$mysqli->close();


//var_dump(json_decode(file_get_contents("php://input")));

?>