注意:未定义索引:第 5 行 C:\wamp\www\CodeCanyon\MCBuddy\Global.php 中的用户名 注意:未定义索引:第 6 行 C:\wamp\www\CodeCanyon\MCBuddy\Global.php 中的密码
这是我的Global.php代码:
session_id();
session_start();
ob_start();
$loggedIn = $_SESSION['Username'];
$Password = $_SESSION['Password'];
$CurrentTime = time();
// MySQL Database Conection Information
define("DBHost", "localhost"); // MYSQL Database Host
define("DBUsername", "root"); // MYSQL Database Username
define("DBPassword", ""); // MYSQL Database Password
define("Database", "mcbuddy"); // MYSQL Database Name
// Establish Connection to MYSQL Database
$db = new mysqli(DBHost, DBUsername, DBPassword, Database);
if ($db->connect_errno) {
echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
}
我的Login.php(我认为错误在这里)
<?php
require 'Global.php';
?>
<div class='well'>
<div style='text-align:center'>
<h2> Sign In </h2>
<center>
<p id='errorMsg' style='background-color: #D11124; width:300px; color:white; text-align:center;'/>
<form action='' method='POST'>
<input type='text' name='Username' placeholder='Username'> <br />
<input type='password' name='Password' placeholder='Password'> <br />
<input class='btn btn-xlarge' type='submit' name='signin' value='Sign In'>
</form>
</div>
</div>
<?php
if(isset($_REQUEST['signin'])) {
$Username = htmlspecialchars(strip_tags($_REQUEST['Username']));
$Password = htmlspecialchars(strip_tags($_REQUEST['Password']));
$p1 = md5($Password);
$UserInfo = $db->query("SELECT * FROM users WHERE Username='$Username'");
$UserI = $UserInfo->fetch_array(MYSQLI_BOTH);
if(empty($Password) || $Password == '') {
echo "
<script type='text/javascript'>
document.getElementById('errorMsg').innerHTML = 'Password is empty!';
</script>
";
}
elseif(empty($Username) || $Username == '') {
echo "
<script type='text/javascript'>
document.getElementById('errorMsg').innerHTML = 'Username is empty!';
</script>
";
}
elseif($UserI['Password'] != $p1) {
echo "
<script type='text/javascript'>
document.getElementById('errorMsg').innerHTML = 'Incorrect username/password';
</script>
";
} else {
$_SESSION['Username']=$Username;
$_SESSION['Password']=$Password;
}
}