Using a form i get the information from the user and i sent it to the DB:
if (isset($_POST['email']) && $_POST['email']!='' && isset($_POST['password']) && $_POST['password']!='' && isset($_POST['nombre']) && $_POST['nombre']!='' && isset($_POST['apellido']) && $_POST['apellido']!='' && isset($_POST['cedula']) && $_POST['cedula']!='') {
$sql="insert into usuario values('','$_POST[email]','".md5($_POST['password'])."','$_POST[nombre]','$_POST[apellido]','$_POST[cedula]','usuario')";
mysqli_query($link,$sql);
if (mysql_error()) {?>
<script> alert("Error en el registro del usuario. Intente de nuevo.");</script> <?php
}
else{
//sin error?>
<script> alert("Usuario registrado exitosamente."); </script> <?php
}
}
else {
//no se reciben los datos?>
<script> alert("Debe rellenar todos los datos."); </script> <?php
}
After the creation of the user the user logins with another form and we get the information that we validate with this code:
<?php
session_start();
include "link.php";
if (isset($_POST['val'])) {
{
switch ($_POST['val']) {
case 1 ://autentificacion de usuario
if (isset($_POST['email']) && $_POST['email']!='' && isset($_POST['password']) && $_POST['password']!='') {
//llegaron los datos
$sql="select * from usuario where email='$_POST[email]'";
$query= mysqli_query($link,$sql);
$num= mysqli_num_rows($query);
if ($num==0) {?>
<script> alert("No existe el usuario")</script><?php
}
else{
//se encontro el registro
$row= mysqli_fetch_array ($query);
if ($row['password'] != md5($_POST['password'])) {
//no coincide contrasenia?>
<script> alert("contrasenia incorrecta");</script><? php
}
else{
//autentificacion
$_SESSION['id_usuario']= $row['id_usuario'];
$_SESSION['nombre']= $row['nombre'];
$_SESSION['apellido']= $row['apellido'];
$_SESSION['cedula']= $row['cedula'];
$_SESSION['tipo']= $row['tipo'];
}
}
}
else {?>
<script> alert("Debe rellenar todos los datos");</script><?php
}`
But after some test it always appears to be an incorrect password. this code is for an assignment so md5 functions is a must. Any ideas?