我的主页上有两个输入框,一个用于用户名,一个用于密码。我有一个 php 文件,它将检查我的数据库以检查这些凭据并允许或拒绝访问。当用户获得访问权限时,我想在我的屏幕上显示,登录为:....“在主页上输入的用户名登录”....
这是我的代码,它检查我的数据库以允许或拒绝访问。
<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="********"; // Mysql password
$db_name="db?K1012904"; // Database name
$tbl_name="AdminUser"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:loginsuccess.php");
}
else {
echo "Wrong Username or Password";
}
?>
这是用户输入凭据的地方
<form name="form1" class="navbar-form pull-right" method="post" action="checklogin.php">
<input name="myusername" type="text" id="myusername" placeholder="Email">
<input name="mypassword" id="mypassword" class="span2" type="text" placeholder="Password">
<button type="submit" name="submit"class="btn">Sign in</button>
</form>
这是我试图显示用户名的地方
<p class="navbar-text pull-right">
Logged in as: <?php echo $myusername ?> </p>
我的问题是我似乎无法显示用户输入的用户名,关于如何让它工作的任何想法?