Hello everyone, I am very new to PHP and I am having difficulty with my login. I can do standard logins via directing to another page, however this one is different.
I would like a login section at the top of my website which is always displayed. If your not logged in then it would always show the login boxes, if you are logged in then it would always display logout. I am also using sessions once you have logged in. I have a feeling I need a loop.
I am rubbish with if and else as I am new to all of this so I appologise if the mistakes are simple. One of the problems I am having is that the messages are being displayed on a seperate page rather than with the rest of my website.
This is what I have so far:
echo" <a href='../admin/logout.php'>Logout</a>";
echo" <form method='post'>";
echo" <label for='username'>Username</label>";
echo" <input type='text' name='username' id='username' />";
echo" <label for='password'>Password</label>";
echo" <input type='password' name='password' id='password' />";
echo" <input type='submit' name='submit' value='Log in' />";
echo" </form>"; //Puts in form if not logged in
echo" <a href='../admin/register.php'>Register</a>";
if(!isset($_POST['submit'])) //if the form has been filled out
$username = $_POST["username"];
$password = md5($_POST["password"]);
$authenticate = mysql_query("select * from customer where username='$username' and password='$password'");
$_SESSION["username"] = $username;
echo "Hello $username"; // a session created
//a session not created, displays form again with login incorrect message