SQL :
$sql = "
UPDATE atributos_prod SET codigo='$codigo', descricao='$descricao', preco='$preco'
WHERE id='$id'
";
The values entered are captured as follows:
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$id = $request->id;
$codigo = $request->item->codigo;
$descricao = $request->item->descricao;
$preco = $request->item->preco;
JSON object $postdata
:
{
"0": {
"codigo": "5",
"descricao": "Bobina",
"preco": "5.0"
},
"1": {
"codigo": "10",
"descricao": "Copo",
"preco": "0.5"
}
}
[The page where the SQL command is run in a 2 second interval]
1st UPDATE [2sec] execution:
|id|codigo|descricao|preco
|1 | 5 | Bobina | 5.0
|2 | 10 | Copo | 0.5
2nd execution of UPDATE [4sec]:
|id|codigo|descricao|preco
|1 | 5 | Bobina | 5.0
|2 | 5 | Bobina | 5.0
3rd UPDATE [6sec] execution:
|id|codigo|descricao|preco
|1 | 5 | Bobina | 5.0
|2 | 10 | Copo | 0.5
that is, the "second" execution of update
is performed incorrectly.
Editing :
print_r($request)
:
stdClass Object
(
[item] => stdClass Object
(
[codigo] => 5
[descricao] => Bobina
[preco] => 5.0
)
[id] => 2
)
stdClass Object
(
[item] => stdClass Object
(
[codigo] => 10
[descricao] => Copo
[preco] => 0.5
)
[id] => 2
)