I have on my home page two input boxes one for the user name and one for the password. I have a php file which will check my database to check these credentials and either allow or deny acces. When the user gains access i want to display on my screen, Logged in as:...."the user name entered on home page to login"....
here is my code which checks my database to allow or deny access.
<?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";
}
?>
Here is where the user will enter credentials
<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>
and here is where i am trying to display the username
<p class="navbar-text pull-right">
Logged in as: <?php echo $myusername ?> </p>
my problem is that i cant seem to display the username entered by the user, any ideas on how i can get this working?