注意:未定义的变量:dbname
未找到用户名
我不能从mysql db获取用户名和密码,也许你知道猫是什么问题?
............................................... .............................................
使page2.php
<?php
session_start();
?>
<html>
<head>
</head>
<body>
<?php
require ('sql_connect.php');
if(isset($_POST['submitlogin'])){
$username = mysql_escape_string($_POST['usernameinput']);
$password = mysql_escape_string($_POST['passwordinput']);
if($username == $dbname){
if($password == $dbpass){
$_SESSION['currentuser'] = $username;
$_SESSION['currentaccesslevel'] = 5;
echo "welcome back, " . $username;
}
else {
showform('wrong password');
}
}
else {
showform("username not found");
}
}
else {
showform("please enter your username and password");
}
function showform($message){
include ('form.php');
echo $message;
}
exit();
mysql_query("SELECT * FROM `user_data` WHERE `username`='$dbname' `password`='$dbpass'");
?>
............................................... ..............................................
sql_connect.php
<?php
mysql_connect("localhost", "root", "") or die("mysql connection is failure.");
mysql_select_db("users") or die("Database does not exists.");
?>
............................................... ................................................ 的 form.php的
<html>
<head>
</head>
<body>
<form method="post" action="page2.php" />
<input type="text" name="usernameinput" />
<input type="text" name="passwordinput" />
<input type='submit' value='submit' name='submitlogin' />
</form>
</body>
</html>
............................................... .........................................
答案 0 :(得分:2)
您必须先定义$dbname
才能使用它们。在上面的代码中,$dbname
未定义,您正在比较它。这就是错误即将到来的原因。
if($username == $dbname){
if($password == $dbpass){
定义他们fisrt
$dbname = //some value;
$dbpass = //some value;
if($username == $dbname){
if($password == $dbpass){