我已经使用PHP,HTML和&amp ;;设置了一个登录系统。 SQLI。它工作正常,但现在不检查登录凭据是否正确。我在标题中有一个if语句,这样当用户成功时,图标会改变并显示用户名。我似乎无法看到错误,建议将不胜感激。
sign_in.php
<div class="wrapper">
<h1>Sign in</h1>
<p class="signup_text">Please sign in to access extra features. Want to comment? Sign in or Sign up! Please use valid credentials.</p>
<form class="form" role="form" method="POST" action="">
<input name="email" type="text" class="email" placeholder="Email" value="<?= $_POST['email'] ?>">
<input name="password" type="password" class="password" placeholder="Password" value="<?= $_POST['password'] ?>">
<input name="login" type="submit" class="submit" value="Sign in">
</form>
<br><br><br>
</div>
header.php(包含html&amp; php)
<div class="menu">
<ul class="list-unstyled">
<? if ($_SESSION['user']['first_name']): ?>
<li><a href="#"><i class="icon fa fa-user"></i>Hello <?= $_SESSION['user']['first_name'] ?></a></li>
<? endif ?>
<li><a href="/"><i class="icon fa fa-home"></i>Home</a></li>
<li><a href="/blog"><i class="icon fa fa-book"></i>Blog</a></li>
<? if ($_SESSION['user']['first_name']): ?>
<li><a href="?action=logout"><i class="icon fa fa-sign-in"></i>Logout</a></li>
<? else: ?>
<li><a href="/sign_in"><i class="icon fa fa-sign-in"></i>Login</a></li>
<li><a href="/register"><i class="icon fa fa-pencil"></i>Register</a></li>
<? endif ?>
</ul>
</div>
mycontrollerclass.php(用于登录的php函数)
function sign_in() {
if ($_POST['login']) {
$db = db();
$result = $db->query("SELECT * FROM `users` WHERE `email` ='" . $_POST['email'] . "'")
if ($result->num_rows > 0)
$data = $result->fetch_assoc();
}
if ($data['password'] == $_POST['password']) {
$this->alerts['success'][] = '<b>Success</b> You have successfully signed in.';
} else {
$this->alerts['error'][] = '<b>Error:</b> Incorrect email or password!';
}
if ($result) {
foreach ($data as $k => $v) {
$_SESSION['user'][$k] = $v;
}
} else {
$this->alerts['error'][] = '<b>Error:</b> Login unsuccessful please try again.';
}
$db->close();
}
}
数据库中的表:
数据库名称:fw_blog ------ 表名:用户------- 列:id,first_name,last_name,url,email,password。
答案 0 :(得分:0)
固定!我愚蠢地把sign ='/ welcome'放在sign_in.php上。这需要是空的。现在工作完美。发布此问题时,我没有保存文件,这就是为什么它不起作用!上面的代码是完美的,没有错误。