J'utilise ce code pour la connexion, mais lorsque j'entre un nom d'utilisateur et un mot de passe, il charge simplement la page et la page de connexion s'affiche à nouveau. Pourquoi cela se produit-il?problème de code de connexion php
<?php
session_start();
if(!isset($_POST['username']) || !isset($_POST['password']) || empty($_POST['username']) || empty($_POST['password']))
{
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to yachts database </title>
<script type="text/javascript">
function validate()
{
var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if(username.length==0)
{
alert("Please enter your user name");
document.getElementById("username").focus();
document.getElementById("username").select();
return false;
}
if(password.length==0)
{
alert("Please enter your password");
document.getElementById("password").focus();
document.getElementById("password").select();
return false;
}
submitOK="false";
}
</script>
<?php
include("styles.txt");
?>
</head>
<body onLoad="self.focus();document.login.username.focus()">
<br><br><br><br><br><br><br>
<center><font size=5 color=blue><b>University of ....... </b></font></center>
<center><font size=5 color=blue><b>Yachts Database Project</b></font></center>
<form name="login" method="post" action="<?php $_SERVER['PHP_SELF'];?>" onSubmit="return validate()">
<table width="350" border="1" align="center" cellpadding=0 cellspacing=0 bgcolor=#ffffff bordercolor=#ffffff>
<tr>
<th colspan=2 height=30 bgcolor=#050E8C><font size=4 color=#ffffff>Please, enter user name and password</font></th>
</tr>
<tr>
<th bgcolor=#E0E0FF><font size=4 color=#2020ff>User name</font></th>
<td bgcolor=#E0E0FF align=center><input type="text" name="username" id="username" size="30"></td>
</tr>
<tr>
<th bgcolor=#E0E0FF><font size=4 color=#2020ff>Password</font></th>
<td bgcolor=#E0E0FF align=center><input type="password" name=" password" id="password" size="30"></td>
</tr>
<tr>
<td bgcolor=#E0E0FF colspan=2 align=right><input type="submit" name="login" value=" Login "> <input type="reset" name="reset" value=" Reset "> <a href=register.php class=links>Register</a> </td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
else
{
$connect= mysql_connect("localhost","root") or die ("Sorry, Can not connect to database");
mysql_select_db("login") or die (mysql_error());
$username1=$_POST['username'];
$password1=$_POST['password'];
if($username1 && $password1)
{
$query="SELECT * FROM users WHERE username='$username1' AND password='$password1'";
$result=mysql_query($query,$connect) or die(mysql_error());
$rowcount=mysql_num_rows($result);
}
if($rowcount)
{
//$_SESSION['username']=$rowcount['username'];
$user1=$username1;
$pass1=$password1;
session_register("user1");
session_register("pass1");
header("location: main.php");
}
else
{
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to yachts database </title>
<script type="text/javascript">
function validate()
{
var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if(username.length==0)
{
alert("Please enter your user name");
document.getElementById("username").focus();
document.getElementById("username").select();
return false;
}
if(password.length==0)
{
alert("Please enter your password");
document.getElementById("password").focus();
document.getElementById("password").select();
return false;
}
submitOK="false";
}
</script>
<?php
include("styles.txt");
?>
</head>
<body onLoad="self.focus();document.login.username.focus()">
<br><br><br><br><br><br><br>
<center><font size=5 color=blue><b>University of ....... </b></font></center>
<center><font size=5 color=blue><b>Yachts Database Project</b></font></center>
<form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onSubmit="return validate()">
<table width="350" border="1" align="center" cellpadding=0 cellspacing=0 bgcolor=#ffffff bordercolor=#ffffff>
<tr>
<th colspan=2 height=30 bgcolor=#050E8C><font size=4 color=#ffffff>Please, enter user name and password</font></th>
</tr>
<tr>
<th bgcolor=#E0E0FF><font size=4 color=#2020ff>User name</font></th>
<td bgcolor=#E0E0FF align=center><input type="text" name="username" id="username" size="30"></td>
</tr>
<tr>
<th bgcolor=#E0E0FF><font size=4 color=#2020ff>Password</font></th>
<td bgcolor=#E0E0FF align=center><input type="password" name=" password" id="password" size="30"></td>
</tr>
<tr>
<td bgcolor=#E0E0FF colspan=2 height=30 align=right><input type="submit" name="login" value=" Login "> <input type="reset" name="reset" value=" Reset "> <a href=register.php class=links>Register</a> </td>
</tr>
<tr>
<td bgcolor=#E0E0FF colspan=2 height=30 align=center><font size=3 color=#ff0000>User name or Password wrong!</font></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
}
?>
peut-être pourriez-vous formater votre code? – bchhun
convenu, je ne peux rien distinguer en ce moment – BrynJ
je ne sais pas comment le formater –