Good morning. I am programming a book cart from a database of books using php sessions. There is very little left for it to work but I'm stuck because the cart does not pick up the added books. I do not put the complete forms only the shipments so they know the data I send.
The scheme is as follows
session not started -> search for books - > add book (the_id) - > register email - > continue search
session started -> search for books - > add book (the_id) - > stay in search results
The user does a search and clicks add book, if it is not registered it asks to add email to log in, and sends book id (works)
$ the_id is the identifier of the book
<input type="text" placeholder="Tu email" name="usuario" required>
<input type="hidden" name="libro" value="<?php echo the_ID() ?>">
<input type="Submit" value="Registrarse"
add book with session started, send book id
$ the_id is the identifier of the book
<input type="hidden" name="libro" value="<?php echo the_ID() ?>">
<input type="submit" value="Añadir a Mis Registros"
I open session
session_start();
I save user email as identifier (it works)
if(isset($_POST['usuario'])){
$usuario = $_POST['usuario'];
$_SESSION['usuario'] = $usuario;
}
If there is a user in session, he / she welcomes you (works)
if($_SESSION['usuario']) { echo "Bienvenido: " . $_SESSION['usuario'] . "";}
I set my session name
if(!isset($_SESSION["random"])) {
$_SESSION["random"] = rand(1,10);
}
$randomNumber = $_SESSION["random"];
I retrieve and save the id of the book. (name book in the form)
if (isset($_POST['libro'])) {
$id = $_POST['libro'];
$_SESSION['libro'] = $id;
}
See My records. If there is a session with added books, show them
if($_SESSION["random"]){
echo $id;
] else {
echo 'no hay registros';
}
The problem is that the cart is empty and therefore shows that there are no records, which makes me suppose that if the session is recorded but the id of the books is not collected. Since I have the books I will send the records by email but I still can not move towards it because the register cart is empty !!
Someone who can guide me ...? thanks!