Ho già inserito il codice per permettere la registrazione ad un sito. adesso sto cercando di realizzare un codice che mi permette di eseguire il login. Immettendo user e password corretti ed inseriti già nel database, il codice mi restituisce "username o password errata" invece di "login effettuato con successo". Perchè?
Ecco il codice:
	
	
	
		
				
			Ecco il codice:
		PHP:
	
	<Doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login</title>
</head>
<body>
<?
$dbcnx=mysql_connect("localhost","root","");
if(!$dbcnx)
	{
	echo("Unable to connect to the database server at this time");
	exit();
	}
$greatfun=mysql_select_db("greatfun",$dbcnx);
if(!@$greatfun)
	{
	exit("Unable to locate the joke database at this time");
	}
if(isset($_POST["submit"]))
	{
	if(!isset($_POST["username"]))
		{
		exit ("Errore: devi inserire il tuo username per continuare!");
		}
	if(!isset($_POST["password"]))
		{
		exit ("Errore: devi inserire la tua password per continuare!");
		}
	$username=$_POST["username"];
	$password=md5($_POST["password"]);
	$q=mysql_query("SELECT * FROM utenti");
	$q2=mysql_fetch_object($q);
	if(($q2->username == $username)&&($q2->password ==$password))
		{
		session_start();
		$_SESSION["logged_in"]=1;
		$_SESSION["username"]=$username;
		$_SESSION["password"]=$password;
		echo("Login avvenuto con successo");
		}
	else	
		{
		echo("Password o username errata");
		}
	}
else
	{
?>
<form name="Login" method="post" action="<?php $_SERVER["PHP_SELF"]; ?> ">
<table>
<tr><td>Username</td><td><input type="text" name="username" size="12" maxlenght="12"></td></tr>
<tr><td>Password</td><td><input type="password" name="password" size="12" maxlenght="12"></td></tr>
<tr><td align="center"><input type="submit" name="submit" class="botton"></td><td><input type="reset" name="reset" value="resetta" class="botton"></td></tr>
</table>
</form>
<?php
	}
?>
</body>
</html>
	
			
				Ultima modifica di un moderatore: