0
I have an array that receives data from a session and I am trying to insert it into the database using foreach but nothing happens. What may be wrong?
Follow an example of the array:
array(3) {
[0]=>
array(4) {
["id_produto"]=>
int(1)
["quantidade"]=>
int(1)
["preco"]=>
string(5) "10,00"
["total"]=>
string(5) "10,00"
}
[1]=>
array(4) {
["id_produto"]=>
int(2)
["quantidade"]=>
int(2)
["preco"]=>
string(5) "45,50"
["total"]=>
string(5) "91,00"
}
}
Follow an example of my code:
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
foreach($_SESSION['dados'] as $produto){
require("conexao.php");
mysqli_query($conexao, "INSERT INTO tb_pedido (
id,id_produto,
id_usuario,
id_categoria,
quantidade,
preco,
total,
data_cadastro,
status)
VALUES (
NULL,
'".$produto['id_produto']."',
'0.0', '0.0',
'".$produto['quantidade']."',
'".$produto['preco']."',
'".$produto['total']."',
NOW(),
'0')") or die(mysql_error());
}
It was exactly the question 2. FLOAT . Thank you. Sometimes we do not pay attention to small things hehe.
– Odair
It happens a lot! Sometimes we lose hours and it ends with a "Was that it?!" does not get angry or relieves.. hehe
– Rogerio Santos