未定义的索引:xampp中的用户名

时间:2015-02-09 16:29:30

标签: php html mysql xampp

我一直在使用和写的一样。但每当我点击它时,都会出错

  

注意:未定义的索引:第3行的D:\ xamp \ htdocs \ xampp \ new \ login.php中的用户名
  注意:未定义的索引:第4行的D:\ xamp \ htdocs \ xampp \ new \ login.php中的密码
  请输入用户名和密码

我的HTML是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="login.php" method="POST">Username:
<input type ='text' name="username" /><br />
password<input type="password" name="password" /><br />
<input type="submit" value="login" /></form>
</body>
</html>

虽然我的PHP是:

<?php

$username = '$_POST[username]';
$password = '$_POST[password]';
if($username && $password)
{
$connect = mysql_connect(“localhost”, “root”, “”); 
$query=mysql_query("SELECT * FROM usres WHERE username=$username");
$numrows = mysql_num_rows($query);
if (!connect) { 
die('Connection Failed: ' . mysql_error()); 
}
   mysql_select_db(“phplogin”, $connect);

}else{
    die("please enter username and password");



    enter code here

}


?>

1 个答案:

答案 0 :(得分:1)

试试这个

<?php

$username = $_POST['username'];
$password = $_POST['password'];
$connect = mysql_connect("localhost", "root", ""); 
if (!$connect) { 
    die('Connection Failed: ' . mysql_error()); 
}
mysql_select_db("phplogin", $connect);

if($username && $password) {
    $query=mysql_query("SELECT * FROM usres WHERE username='".$username."' ");
    $numrows = mysql_num_rows($query);
    if($numrows > 0){
        //redirect to other page
    }else{
        echo "please enter username and password";
    }
} else {
    echo "please enter username and password";
}

?>