我正在制作一个登录页面,您应该在其中使用用户名和密码才能登录。在登录之前,您需要使用您的姓名注册一个帐户。这是我登录页面的代码:
<?php
// if already logged in
if(isset($_SESSION['username']) && isset($_SESSION['password'])) {
if(isset($_POST['logout'])) {
session_destroy();
echo 'Logged Out!';
showloginform();
}
else {
print("<p>Dear $_SESSION[username]</p>");
print "<p>only a logged in user can see this</p>";
}
}
//not logged in:
else {
//have login request:
if(isset($_POST['username']) && isset($_POST['password'])) {
include 'opendb.php';
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT Name, password FROM Restaurant_table WHERE Name = '$username' AND password = '$password'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
//found username/password combination:
if (mysql_num_rows($result) == 1) {
$_SESSION['logged'] = true;
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
echo 'logged in';
//exit;
}
else {
echo 'Sorry, wrong user_id or password.';
}
}
//have no login request:
else {
showloginform();
}
}
function showloginform() {
echo "\r\n please enter your login information to proceed with our site <br/><br/>";
echo '<form action="start.html" method="post">';
echo '<div class="input-group">';
echo '<input type="text" placeholder="User ID" name="username" class="input-transparent" id="email" />';
echo '<input type="password" placeholder="password" name="password" class="input-transparent"/>';
echo '</div>';
echo '<button id="login-submit" type="submit" class="login-button">Manager Login</button>';
echo '</form>';
}
function checkpass() {
include 'opendb';
$sql = "select * from Restaurant_table where Name='$_POST[username]' and password='$_POST[password]'";
$result = mysql_query($sql,$conn) or die(mysql_error());
return mysql_num_rows($result);
}
?>
但它似乎不起作用,首先当我使用错误信息登录时它不会给我任何错误它只是移动到下一页。假设给我一个错误或什么,我不确定出了什么问题。