Generate the following comparison :
<?php
if($_SESSION['id_nivel'] == 1 || 2){
?>
<div class="col-md-6">
<select name="cantidad" class="form-control">
<option class="form-control" value="1">1</option>
<option class="form-control" value="2">2</option>
<option class="form-control" value="3">3</option>
<option class="form-control" value="4">4</option>
<option class="form-control" value="5">5</option>
</select>
</div>
<input name="id_producto" type="hidden" value="<?php echo $columnas["id_producto"];?>">
<div class="col-md-6" id="carrito">
<button type="submit" id="boton-add" class="btn bg-lim white" alt="Agregar al carrito" title="Agregar al carrito">
Añadir al carrito <i class="fa fa-shopping-cart" aria-hidden="true"></i>
</button>
</div>
<?php
} else{
echo '<div class"col-md-6 col-xs-6 col-sm-6 col-6 col-lg-6 col-lx-6>
<a data-toggle="modal" data-target="#createacc">Crear Cuenta</a> o
<a data-toggle="modal" data-target="#login">Iniciar Sesión</a>
</div>';
}
?>
But it generates the following notice :
Notice: Undefined index: id_nivel
I understand that it is because an id_level is not set to the $_SESSION since it is not registered, that is, when creating a user, id_user and id_level are set , so the verification of both parties can be generated.
Clarification : I thought of this method of hiding the button: Add to Cart, since when an id_level or user is not registered, pressing Add to Cart generates missing $variables etc. errors.
My question :
How do I detect if a $_SESSION has id_level or not?
Namely:
level_id = 1 (Administrator) || 2 (User)
No level: Visit;
I was able to fix it with
isset()
I leave the code:
It was solved in this way since the visitor when entering does not establish any
id_nivel
(only for users) so when he does not have it , heid_nivel
executes theelse
You could do this when registering the visitor, if you need more parameters you have to add them.