为什么php显示mysqli_close错误

时间:2015-03-25 09:43:21

标签: php mysqli

我在php中构建了一个简单的登录页面。当我尝试运行此页面时,它会显示错误信息..

“注意:未定义的变量:第53行的C:\ wamp \ www \ user \ login.php中的conn” “警告:mysqli_close()期望参数1为mysqli,在第53行的C:\ wamp \ www \ user \ login.php中给出null”

当我尝试登录而不提供任何输入时会出现此错误。

代码如下。

<html>
<head>
<body>

<form method="post" action="<?php echo$_SERVER['PHP_SELF'];?>">
Username:<input type="text" name="username" ><br>
Password:<input type="password" name="password" >
<input type="submit" value="login">
</form>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$servername="localhost";
$username="root";
$password="";
$dbname="Login";
$username1=$_REQUEST["username"];
$password1=$_REQUEST["password"];
if($username1=="" || $password1=="")
{
echo"Please Fill the form";
}
else
{
$conn=mysqli_connect($servername,$username,$password,$dbname);
if(!$conn)
{
die("Conection Failed".mysqli_error($conn));
}
$sql="select * from Username where username='$username1' and 
password='$password1'";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0)
{
while($row=mysqli_fetch_assoc($result))
{
$username2=$row["username"];
$password2=$row["password"];
if($username2==$username1 && $password2==$password1)
{
echo"Password match";
}
else
{
echo"Password not match";
}
}
}
else
{
echo"No results found";
}
}
mysqli_close($conn);
}

else
{
}
?>

</body>
</head>
</html>

0 个答案:

没有答案