0
I’m using the following code unsuccessfully.
$conn = mysqli_connect('localhost','user','pass','banco');
try {
$body = file_get_contents("php://input");
$dados = json_decode($body);
foreach($dados as $dataone){
$nome = $dataone['nome'];
$img = $dataone['img'];
$qtd = $dataone['qtd'];
$sql = "INSERT into tabela (nome,img,qtd) values ('{$nome}','{$img}','{$qtd}')";
$qr=mysqli_query($conn,$sql);
}
What is the problem ? Is returning error ? ..
– NoobSaibot
You’re not saving
– Henrique Mendes Silveira Rodri
Now that I’ve noticed, there’s a simple quotation mark missing here:
({$nome}',
– NoobSaibot
That was the problem ?
– NoobSaibot
It wasn’t... It’s a json that comes from the APP and saved in the bank, if run out of the is it always saves the last line, nas inside the is not saved anything
– Henrique Mendes Silveira Rodri
Friend, put the code of the JSON file that is being sent, without it it becomes difficult to answer your question. The problem here is that you are treating the decoded JSON file as an array, but in fact it is an object with several attributes. You need to know how these attributes are organized in order to be able to write them to the database correctly.
– CloudAC
@Cloudac, is thus sending to php: { name: "Pedro", img: "images/pedro.png", Qtd: "5"}, { name: "João", img: "images/Joao.png", Qtd: "8"}, { name: "Jose", img: "images/Jose.png", Qtd: "7"}
– Henrique Mendes Silveira Rodri