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

if (!$_SESSION["manu"]) {
    http_response_code(401);
    die();
}

$manu = $_SESSION["manu"];

//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");
include_once("db_connect.php");
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 
            photo4 = '" .$base64. "' 
              WHERE manu = '" .$manu. "' AND nfc = '" .$postData->id. "' ";

            
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);
}



echo "Success: Record updated. [".$query."]";
http_response_code(200);


$mysqli->close();

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

?>