我正在制作一个页面,你应该使用user_name和密码才能使用。登录前,您需要注册一个包含您姓名的帐户。 这是我登录页面的代码:
<?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);
}
?>
但似乎它不起作用,首先,当我使用错误信息登录时,它不会给我任何错误它只是移动到下一页。假设给我一个错误或omething,我不知道出了什么问题。
答案 0 :(得分:4)
您正在使用start.html
的{{1}}页面操作。因此,它会重定向到<form>
而不是start.html
。改变这个
start.php
到
echo '<form action="start.html" method="post">';
引用囚犯
echo '<form action="start.php" method="post">';
答案 1 :(得分:3)
是的,首先你必须在php页面而不是html页面中发布值。
echo '<form action="<?php echo $_SERVER[\'PHP_SELF\']?>" method="post">';
第二个错误是
if (mysql_num_rows($result) == 1) {
而不是它应该是。
if (mysql_num_rows($result)> 0) {