login.php
Código PHP:
<?php
session_start();
include('conex.php');
if (isset($_POST['email'])) {
$email=$_POST['email'];
$pass=$_POST['pass'];
if($email == NULL){echo "<font color=red>No es pot deixar en blanc el correu electrònic.</font>";}
elseif ($pass == NULL) {echo "<font color=red>No es pot deixar en blanc la contrasenya.</font>";}
else{
$query = mysql_query("SELECT * FROM user WHERE email = '$email'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['email'] != $email) {
echo "<font color=red>Aquest correu electrònic no està registrat.</font>";
}elseif($data['pass'] != $pass){
echo "<font color=red>Contrasenya incorrecta.</font>";
}else{
$query = mysql_query("SELECT * FROM user WHERE email = '$email'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION['login']=$row['email'];
echo "<script type='text/javascript'>location='perfil.php'</script>";
}
}
}
?>
<form name="form2" method="post" action="login.php">Correu electrònic:</td><td>
<input name="email" type="text" "></td></tr>
<tr><td> <br>Contrasenya:</td><td>
<input name="pass" type="password" id="pass"></td></tr>
<tr><td colspan=2><center><input type="submit" name="Submit" value="Inicia sessió"></center></td></tr>
</form>
Código PHP:
$nom = mysql_query("SELECT * FROM user WHERE email = '".$_SESSION['login']."'") or die(mysql_error());
$row = mysql_fetch_array($nom);