他的以下代码有问题。出现的两条错误消息是
Notice: Use of undefined constant myusername - assumed 'myusername' in C:\Program Files\wamp\www\login_success.php on line 3
Deprecated: Function session_is_registered() is deprecated in C:\Program Files\wamp\www\login_success.php on line 3
Login Successful
但是仍然显示登录成功,即使最初没有输入任何信息。
您在任何地方的帮助将不胜感激。
HTML
会员登录 用户名: 密码:CSS
<?php
$host="localhost";
$username="root";
$password="";
$db_name="Hockey Club";
$tbl_name="members";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
和 - login_success.php
<?php
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>