<?php
session_start();
$con=mysqli_connect("localhost","xxx","xxxxxx","xxx");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$eadd = $_POST['eadd'];
$pass = $_POST['pass'];
$eadd = htmlspecialchars(stripslashes(strip_tags($eadd)));
$pass = htmlspecialchars(stripslashes(strip_tags($pass)));
if (filter_var($eadd, FILTER_VALIDATE_EMAIL)) {
$sql = mysql_query("SELECT * FROM accounts WHERE Emailadd = '$eadd' AND Password = '$pass'");
if(!$sql){
die('There was an error in query '. mysql_error());
}
$count = mysql_numrows($sql) or die(mysql_error());
if ($count<=0)
{
echo "
<html>
<style>
body{
background-color:#cccccc;
}
#error{
position:relative;
margin:auto;
top:20px;
width:320px;
height:55px;
background-color:#63a8d7;
border:1px solid #2a262a;
}
#errorC{
position:absolute;
top:20px;
left:20px;
font: 14px arial, tahoma;
}
</style>
<body>
<div id=error>
<div id=errorC>
Incorrect Email Address and Password! <a href=index.php>GO BACK</a>
</div>
</div>
</body>
</html>
";
}
else
{
//have them logged in
$_SESSION['account'] = $eadd;
header('location:home.php');
}
mysqli_close($con);
} else {
echo "
<html>
<style>
body{
background-color:#cccccc;
}
#error{
position:relative;
margin:auto;
top:20px;
width:320px;
height:55px;
background-color:#63a8d7;
border:1px solid #2a262a;
}
#errorC{
position:absolute;
top:20px;
left:20px;
font: 14px arial, tahoma;
}
</style>
<body>
<div id=error>
<div id=errorC>
Invalid Email Address! <a href=index.php>GO BACK</a>
</div>
</div>
</body>
</html>
";
}
?>
为什么会出现“未选择数据库”错误?我的 mysqli_connect 是正确的。我有另一个注册 php 代码,使用它我可以使用该连接注册一些电子邮件地址。但是在登录 php 代码中,我无法使用用户电子邮件地址登录。