I have the following code for a login form, from a previous page I sent by POST method the variable id_modulo
and I recover it in the login page, but if the user miswrites the password or the name of user the system stays in the same page since the action of the form is $_SERVER['PHP_SELF']
. In this same form I have a hidden field to save the result of the variable id_modulo
, but it happens that when reloading the page for the above reason (user or bad password) I can not recover the value of id_modulo
, it gives me the error of:
Notice: Undefined index: module_id in C: \ xampp \ htdocs \ security \ questionnaire \ loginp.php on line 67
Code of the page:
$loginFormAction = $_SERVER['PHP_SELF'];
$id_modulo = $_POST['id_modulo'];
if ($id_modulo == "todos") {
echo "<h3>CUESTIONARIO CON TODOS LOS MODULOS</h3>";
}else{
$SQLModulo = "SELECT * FROM modulos WHERE id_modulo='$id_modulo'";
$SQLconsultaModulo = $conexionmysqli->query($SQLModulo);
$SQLconsultaModulo->data_seek(0);
$row_nombreModulo = $SQLconsultaModulo->fetch_assoc();
$nombreModulo ="".$row_nombreModulo['n_modulo']."";
$SQLconsultaModulo->close(); // Liberar memoria usada por consulta.
echo "<h3>$nombreModulo</h3>";
}
<form role="form" id="login" name="form_ingreso" method="post" action="<?php echo $loginFormAction; ?>">
<input type="text" name="id_modulo" id="id_modulo" value="<?php echo"$id_modulo"; ?>">
<fieldset>
<div class="form-group input-group">
<span class="input-group-addon">Usuario</span>
<input type="text" class="form-control field required" name="usuario" id="login_username" value="" placeholder="..." data-toggle="tooltip" title="Teclee su nombre de usuario" data-placement="bottom" autofocus>
</div>
<div class="form-group input-group">
<span class="input-group-addon">Contraseña</span>
<input type="password" class="form-control field required" name="contrasena" value="" id="login_password" placeholder="..." data-toggle="tooltip" title="Teclee su contraseña" data-placement="bottom">
</div>
<p class="help-block"><em>Verifique que la tecla Block Mayús (CAPS LOCK) no este activada.</em></p>
<!-- Change this to a button or input when using this as a form -->
</fieldset>
</div>
<div class="panel-footer">
<div class="btn-group">
<button type="submit" class="btn btn-primary btn-sm">ACCEDER</button>
</div>
<span class="pull-right"><a href="../" class="btn btn-danger btn-sm">REGRESAR</a></span>
</div>
</form>