Good afternoon, classmates.
I would like to save in a session variable the value of two fields that I pass through $ _post from a form and that this session variable will store the data of those fields until I destroy it with the intention of filling a table with the data stored in it.
Can someone tell me how to store the form data in a session array?
I am using Php. My code is the following but I have an error of:
Array String conversion.
$art = $_POST["select-productos"];
$und = $_POST["und-productos"];
$productos = array("articulo" => $art, "cantidad" => $und);
if (empty($_SESSION["listadecompra"])) {
$i = 0;
$_SESSION["listadecompra"][$i] = $productos;
} else {
$i = count($_SESSION["listadecompra"]);
$i++;
$_SESSION["listadecompra"][$i] = $productos;
}
/* Creamos tabla de contenido */
$listado = $_SESSION["listadecompra"];
foreach ($listado as $value) {
echo "<tr><td>" . $value . "</td><td>" . $value . "</td></tr>";
}
//var_dump($_SESSION["listadecompra"]);
echo "Total de productos: " . $i . "<br>";
What I intend is to be able to increase the array that I store in the session with the data I am receiving from the form and then display them in a table.
Greetings.