I am starting a simple login and registration with php and mysql. I am stuck on this php code. Functions.php and connect.php pages are setup as well and they do connect to the database. Login.php
Need help with a login form.
8
I am starting a simple login and registration with php and mysql. I am stuck on this php code. Functions.php and connect.php pages are setup as well and they do connect to the database.
Login.php
dologin.php
Can anyone identify what might be wrong in the php code above?
Login.php
HTML Code:
<html> <head> <title>Basic CMS - Admin Area Login</title> </head> <body> <?php session_start(); if(isset($_SESSION['user'])) { header('Location: index.php'); } else { ?> <form action="dologin.php" method="POST" > <input type="text" name="username" > <input type="password" name="password"> <input type="submit" value="Login"> <?php } ?> </body> </html>
PHP Code:
<?php
include ('../includes/functions.php');
if(isset($_POST['login'])) {
if(isset($_POST['username'])) {
if(isset($_POST['password'])) {
$username = $_POST['username'];
$query = mysql_query("SELECT * FROM users WHERE Username = '$username'") or die(mysql_error());
$user = mysql_fetch_array($query);
if ($_POST['password'] == $user['Password']) {
echo "Login successful";
$_SESSION['user'] = $user['Username'];
header("Location: index.php");
} else {
echo "Please check your login details";
include('login.php');
}
} else {
echo "Please check your password";
include('login.php');
}
} else {
echo "Please check your username";
include('login.php');
}
} else {
echo "Please check that you have filled out the login form";
include('login.php');
}
?> - Andrew H
- man5
- Andrew H
- Andrew H
- man5
- Andrew H
- [1] reply
- man5
Next Topics on Trending Feed
-
8