Whenever I fill the email and password tabs, then press the login button, nothing seems to happen nothing loads or gets submitted. However I leave both email and passwords tabs blank, then press the login button an error of invalid username or password will show up.
<?php
session_start();
if(isset($_POST['submit'])) {
include_once("php/config/database.php");
$Email = strip_tags($_POST['Email']);
$Password = strip_tags($_POST['Password']);
$Email = stripslashes($Email);
$Password = stripslashes($Password);
$Email = mysqli_real_escape_string($conn, $Email);
$Password = mysqli_real_escape_string($conn, $Password);
$Password = md5($Password);
$sql = "SELECT * FROM Users WHERE Email='$Email' LIMIT 1";
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($query);
$UserID = $row['UserID'];
$conn_Password = $row['Password'];
if($Password == $conn_Password) {
$_SESSION['Email'] = $Email;
$_SESSION['UserID'] = $UserID;
header("Location: account.php");
} else {
echo "You didn't enter the correct details!";
}
}
?>
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>background</title>
<link rel="stylesheet" href="css/style.css">
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</head>
<body>
<div class="container demo-1">
<div class="content">
<div id="large-header" class="large-header">
<form action="index.php" method="POST" />
<div class="box">
<h1 id="logintoregister">Login</h1>
<div class="group show">
<input class="inputMaterial" type="text" name="FirstName" >
<span class="highlight"></span>
<span class="bar"></span>
<label>First Name</label>
</div>
<div class="group show">
<input class="inputMaterial" type="text" name="Surname" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Surname</label>
</div>
<div class="group ">
<input class="inputMaterial" type="email" name="Email" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
<div class="group">
<input class="inputMaterial" type="password" id="password" name="Password" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Password</label>
</div>
<div class="group show">
<input class="inputMaterial" type="password" id="confirm_password" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Confirm Password</label>
</div>
<button id="buttonlogintoregister" type = "submit" name="submit">Login</button>
<p id="plogintoregister">By registering, You accept all terms and conditons </p>
<p id="textchange" onclick="register()"> Sign Up</p>
</form>
<!-- Related demos -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
> JS code
var cont = 0;
function register(){
cont++;
if(cont==1){
$('.box').animate({height:'600px'}, 550);
$('.show').css('display','block');
$('#logintoregister').text('Register');
$('#buttonlogintoregister').text('Register');
$('#plogintoregister').text("Sei gia' registrato?");
$('#textchange').text('Login');
}
else
{
$('.show').css('display','none');
$('.box').animate({height:'365px'}, 550);
$('#logintoregister').text('Login');
$('#buttonlogintoregister').text('Login');
$('#plogintoregister').text("Non sei iscritto?");
$('#textchange').text('Register');
cont = 0;
}
}
var password = document.getElementById("password")
, confirm_password = document.getElementById("confirm_password");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
Related
I want to set default user ( Trainees role ) for newly registered user on my system.
My main problem is registration works but the 'role' tab on the database is empty. Tried adding dropdown button for trainees role but the 'role' tab on the users table is still empty.
Is it allowed to set default user role upon user registration?
Database Image
Registration.php code
<?php
// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
require_once "php/dbconnect.php";
if(isset($_SESSION['user_id'])!="") {
header("Location: index.php");
}
if (isset($_POST['signup'])) {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$name = mysqli_real_escape_string($conn, $_POST['name']);
$emailid = mysqli_real_escape_string($conn, $_POST['emailid']);
$age = mysqli_real_escape_string($conn, $_POST['age']);
$location = mysqli_real_escape_string($conn, $_POST['location']);
$role = mysqli_real_escape_string($conn, $_POST['role']);
if (!preg_match("/^[a-zA-Z ]+$/",$name)) {
$name_error = "Name must contain only alphabets and space";
}
if(!filter_var($emailid,FILTER_VALIDATE_EMAIL)) {
$email_error = "Please Enter Valid Email ID";
}
if(strlen($password) < 6) {
$password_error = "Password must be minimum of 6 characters";
}
if(strlen($mobile) < 10) {
$mobile_error = "Mobile number must be minimum of 10 characters";
}
if($password != $cpassword) {
$cpassword_error = "Password and Confirm Password doesn't match";
}
if(mysqli_query($conn, "INSERT INTO user(username,password,name,emailid,age,location,role) VALUES('" . $username . "', '" . md5($password) . "', '" . $name . "', '" . $emailid . "','" . $age . "','" . $location . "','" . $role . "')")) {
header("location:http://localhost/test/?url=users_index");
exit();
} else {
$error = 'Invalid Username or Password';
}
mysqli_close($conn);
}
?>
Registration Form:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>G&L Management System</title>
<!-- BOOTSTRAP STYLES-->
<link href="css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="css/font-awesome.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
<style>
#font-face {
font-family: Poppins;
src: url("fonts/Poppins-Regular.ttf");
}
html * {
font-family: "Poppins", sans-serif;
}
.myhead{
margin-top:0px;
margin-bottom:0px;
text-align:center;
}
</style>
</head>
<body>
<center>
<img src="banner.png" style="width: 300px; height: 250px;">
</center>
<div class="container">
<div class="row ">
<div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
<div class="panel-body" style="background-color: #E2E2E2; margin-top:70px; box-shadow: 5px 10px #888888;">
<h3 class="myhead">User Registration</h3>
<form role="form" action="register.php" method="post">
<br>
<label>Username</label>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-user" ></i><?php if (isset($username_error)) echo $username_error; ?></span>
<input type="text" class="form-control" placeholder="Username" name="username" required />
</div>
<label>Password</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-lock" ></i><?php if (isset($password_error)) echo $password_error; ?></span>
<input type="password" class="form-control" placeholder="Password" name="password" required />
</div>
<label>Name</label>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-user" ></i><?php if (isset($name_error)) echo $name_error; ?></span>
<input type="text" class="form-control" placeholder="Name" name="name" required />
</div>
<label>Email</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-envelope" ></i><?php if (isset($emailid_error)) echo $emailid_error; ?></span>
<input type="text" class="form-control" placeholder="Email" name="emailid" required />
</div>
<label>Age</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-child" ></i><?php if (isset($age_error)) echo $age_error; ?></span>
<input type="number" class="form-control" placeholder="Age" name="age" required />
</div>
<label>Location</label>
<div class="form-group input-group">
<span class="input-group-addon"><i class="fa fa-map-marker" ></i><?php if (isset($location_error)) echo $location_error; ?></span>
<input type="text" class="form-control" placeholder="Location" name="location" required />
</div>
<div>
<input type="submit" class="btn btn-success" name="signup" value="Submit">
<div class="form-group text-center">
<div class="col-sm-12 mt-3">
Already have an account?
<p>Login Here</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
You can simply set default value for column "role" to trainee, that way whenever new user is created it is assigned role of trainee automatically.
ALTER TABLE `user`
ALTER `role` SET DEFAULT "trainees";
otherwise you can add drop down like this
<label for="role">Choose a role:</label>
<select id="role" name="role">
<option value="admin">Admin</option>
<option value="coach">Coach</option>
<option value="trainees">Trainees</option>
</select>
I am new on PHP and I trying to make a simple login system. I want that when i login, if I submit incorrect information system gives validation error and if I submit true info I want to get email or name in profile blade.
Like hello $user!!!
Login page
<html>
<title>Login Form</title>
<body>
<div class="container">
<form class="" method="post">
<label for="email">Enter Your Email</label>
<input type="text" name="email"> <br/>
<label for="password">Enter Your Password</label>
<input type="password" name="pass"><br/>
<input type="submit" value="Login" name="submit">
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$email=$_POST['email'];
$pass=$_POST['pass'];
if(($email=="cagri#vargonen.com") && ($pass=="1234")){
header()
}
else{
echo "Invalid username/password";
}
}
?>
In login page, I tried;
<?php
$email = $_POST['email'];
$password = $_POST['pass'];
if($email == 'cagri#vargonen.com' && $password == '1234'){
echo "Welcome Çağrı Uğurel";
}
else{
echo "Your email or password incorrect";
}
?>
Can you please help me where is my mistake?
You need to use session_start() to get username or other temp variables.
<?php
session_start();
if (isset($_POST["submit"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$actualuser = "cagri#vargonen.com";
$actualpass = "1234";
if (($email == $actualuser) && ($pass == $actualpass)) {
$_SESSION["username"] = $username;
header("location:somepage.php");
} else {
echo "Username or Password isn't matched.";
}
}
?>
And if login is succeed, username goes to session variable which means you can use that variable during the session.
somepage.php
<?php
session_start();
?>
<html>
<title>User Page</title>
<body>
<p><?php echo $_SESSION["username"];?> </p>
</body>
</html>
I suggest you to use ajax method for kind of these.
EDIT:
Here is real-life example from my previous project.
index.php
<div class="modal fade" id="loginmodal" role="dialog" data-backdrop="static">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="padding:35px 50px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1> Giriş yap</h1>
</div>
<div class="modal-body" style="padding:40px 50px;">
<form role="form" method="post" action="index.php">
<div class="form-group">
<label for="usrname"><span class=""></span> Kullanıcı Adı</label>
<input type="text" pattern="[a-z]*"class="form-control" id="usrname" name="username" placeholder="Yetkili veya normal kullanıcı adı giriniz" required>
</div>
<div class="form-group">
<label for="psw"><span class=""></span> Şifre</label>
<input type="password" class="form-control" id="psw" name="password" placeholder="Şifre" required>
</div>
<button type="submit" class="btn btn-success btn-block" name="login"><span class=""></span> Giriş</button>
</form>
</div>
logincheck.php
<?php
if(isset($_POST["login"])){
$username = $_POST["username"];
$password = $_POST["password"];
$query = $db->prepare("select * from users where username=:username AND password=:password");
$query->execute(array(
':username' => $username,
':password' => $password
));
$r = $query->fetch();
$count = $query->rowCount();
if($count > 0 && $r["rank"] > 0) {
$_SESSION["username"] = $username;
$_SESSION["rank"] = $r["rank"];
header("location:project.php");
}
}
?>
userpage.php
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"> <?php echo $_SESSION["username"];?> <span class="caret">
</span></a>
<ul class="dropdown-menu">
<li>Çıkış yap</li>
</ul>
</li>
</ul>
Hope, this is help!
Add semicolon here header();
<html>
<title>Login Form</title>
<body>
<div class="container">
<form class="" method="post">
<label for="email">Enter Your Email</label>
<input type="text" name="email"> <br/>
<label for="password">Enter Your Password</label>
<input type="password" name="pass"><br/>
<input type="submit" value="Login" name="submit">
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['submit'])){
session_start();
$email=$_POST['email'];
$pass=$_POST['pass'];
if(($email=="cagri#vargonen.com") && ($pass=="1234")){
$_SESSION['user'] = array('email'=>$email);
echo 'Hello '.$_SESSION['user']['email'].'...!';
}
else{
echo "Invalid username/password";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
$con = mysql_connect('localhost', 'root','');
mysql_select_db ('product');
echo "Connected to database";
session_start();
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Register</title>
<script type="text/javascript" src="assets/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<link rel="stylesheet" href="reg.css" />
<!-- Google Fonts -->
<link href='https://fonts.googleapis.com/css?family=Passion+One' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
<script src="jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<table align="center">
<td>
<tr>
<div align="center" style="size:30%;" class="container">
<div class="row main" style="width:30%;">
<div class="panel-heading">
<div class="panel-title text-center">
<h1 class="title">Register Here</h1>
<hr />
</div>
</div>
<div class="main-login main-center">
<form class="form-horizontal" method="post" action="<?php
echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div align="left" class="form-group">
<label name="name" class="cols-sm-2 control-label">Your Name</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="name" placeholder="Enter your Name"/>
</div>
</div>
</div>
<div align="left" class="form-group">
<label name="email" class="cols-sm-2 control-label">Your Email</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="email" placeholder="Enter your Email"/>
</div>
</div>
</div>
<div align="left" class="form-group">
<label name="user_name" class="cols-sm-2 control-label">Username</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-users fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="user_name" placeholder="Enter your Username"/>
</div>
</div>
</div>
<div align="left" class="form-group">
<label name="password" class="cols-sm-2 control-label">Password</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
<input type="password" class="form-control" name="password" placeholder="Enter your Password"/>
</div>
</div>
</div>
<div align="left" class="form-group">
<label name="confirm_password" class="cols-sm-2 control-label">Confirm Password</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock fa-lg" aria-hidden="true"></i></span>
<input type="password" class="form-control" name="confirm_password" placeholder="Confirm your Password"/>
</div>
</div>
</div>enter code here
<div align="left" class="form-group ">
<button type="button" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>
</div>
<div class="login-register">
Already registered? Login here
</div>
</form>
</div>
</div>
</div>
</tr>
</td>
</table>
<?php
if (isset($_POST['submit']))
{
$name = $_POST['name'];
$username = $_POST['user_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['confirm_password'];
$slquery = "SELECT * FROM customer WHERE email = '$email'";
$selectresult = mysql_query($slquery);
if(empty($_POST['name']))
{
$nameErr='Enter Your Name!';
}
else
{
$user = test_input($_POST['name']);
if(!preg_match('/^[a-zA-Z0-9#_]*$/',$user))
{
$nameErr=' Re-Enter Your Name! Format Inccorrect!( only alpha, numbers,#_ are allowed)';
}
}
if(empty($_POST['password']))
{
$passErr='Enter Your Password!';
}
else
{
$user = test_input($_POST['password']);
if(!preg_match('/^[a-zA-Z0-9#_]*$/',$pass))
{
$passErr='Invalid Format! Re-Enter Password!';
}
}
if(mysql_num_rows($selectresult)>0)
{
$msg = 'email already exists';
}
elseif($password != $cpassword){
$msg = "passwords doesn't match";
}
else{
$query = "INSERT INTO customer (name,email,user_name, password,confirm_password, ) VALUES ('
$name', '$username', '$password', '$cpassword', '$email')";
$result = mysql_query($query);
if($result){
$msg = "User Created Successfully.";
}
}
}
?>
</body>
</html>
I am trying to create a registration form with validation.i used some bootstrap for the front end design then Mysql database along with php.
when I click to submit the registration form, it does not validate the field values.please, someone, tell me what's wrong with this.Also, it's not showing the errors. I don't know why this is not working.
Thank you in Advance.
Just change this line from
<button type="button" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>
to
<button type="submit" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>
You have used button so form is not submitted. Change it to submit type
EDIT
Note: please start using PDO or mysqli
Please check below point:
1) You have used test_input() but not defined in your shown code.
2) Your query have extra , after confirm_password.
3) Insert query will not work. There were some errors:
$query = "INSERT INTO customer (name,user_name, password,confirm_password, email) VALUES ('
$name', '$username', '$password', '$cpassword', '$email')";
4) No need to store confirm_password
Database
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "stackoverflow";
// Create connection
$conn = new mysqli($servername, $username, $password,$database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
session_start();
?>
Change the Register button like this
<div align="left" class="form-group ">
<button type="submit" name="submit" class="btn btn-primary btn-lg btn-block login-button">Register</button>
</div>
test_function
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
Full PHP
<?php
if (isset($_POST['submit']))
{
$name = $_POST['name'];
$username = $_POST['user_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$cpassword = $_POST['confirm_password'];
$slquery = "SELECT * FROM customer WHERE email = '$email'";
$selectresult = mysqli_query($conn,$slquery);
if(empty($_POST['name']))
{
$nameErr='Enter Your Name!';
}
else
{
$user = test_input($_POST['name']);
if(!preg_match('/^[a-zA-Z0-9#_]*$/',$user))
{
$nameErr=' Re-Enter Your Name! Format
Incorrect!( only alpha, numbers,#_ are allowed)';
}
}
if(empty($_POST['password']))
{
$passErr='Enter Your Password!';
}
else
{
$user = test_input($_POST['password']);
if(!preg_match('/^[a-zA-Z0-9#_]*$/',$password))
{
$passErr='Invalid Format! Re-Enter Password!';
}
}
if (mysqli_num_rows($selectresult)>0)
{
echo 'email already exists';
}
elseif($password != $cpassword){
$msg = "passwords doesn't match";
}
else{
var_dump($name.$email.$username.$password.$cpassword);
$query = "INSERT INTO customer(name,email,user_name,
password,confirm_password) VALUES ('
$name', '$email','$username', '$password', '$cpassword')";
if ($conn->query($query) === TRUE) {
echo "New user created successfully";
} else {
echo "Error: " . $query . "<br>" . $conn->error;
}
$conn->close();
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}?>
I've reset my database and on registration, we added random salt to hashes, and the registration script worked fine, we could create accounts and accounts with the same password and they had different hashes, but our login script is broken, not logging in users, saying their password is incorrect.
No idea why- we have spent the last 2 hours trying to fix it. We have used PHP error checkers(https://phpcodechecker.com/), nothing was wrong.
We are running an old version PHP(5.6) and MySQL and can't currently change.
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
// it will never let you open index(login) page if session is set
if ( isset($_SESSION['user'])!="" ) {
header("Location: index.php");
exit;
}
$error = false;
if( isset($_POST['btn-login']) ) {
// prevent sql injections/ clear user invalid inputs
$email = trim($_POST['email']);
$email = strip_tags($email);
$email = htmlspecialchars($email);
$name = trim($_POST['name']);
$name = strip_tags($name);
$name = htmlspecialchars($name);
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
// prevent sql injections / clear user invalid inputs
if(empty($name)){
$error = true;
$nameError = "Please enter your username.";
}
if(empty($pass)){
$error = true;
$passError = "Please enter your password.";
}
$res=mysql_query("SELECT userId, userEmail, userPass, userSalt, userSalt2 FROM users WHERE userName='$name'");
$row=mysql_fetch_array($res);
$row['userSalt']=$salt1;
$row['userSalt2']=$salt2;
// if there's no error, continue to login
if (!$error) {
$passwordHash = hash('sha256', $salt1 . $password . $salt2); // password hashing using SHA256
//$res=mysql_query("SELECT userId, userEmail, userPass, userSalt, userSalt2 FROM users WHERE userName='$name'");
//$row=mysql_fetch_array($res);
$count = mysql_num_rows($res); // if email/pass correct it returns must be 1 row
if( $count == 1 && $row['userPass']==$passwordHash ) {
$_SESSION['user'] = $row['userId'];
header("Location: dashboard.php");
} else {
$errMSG = "Incorrect Credentials, Try again...";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function(){
$("#overallhead").load("overall_header.php");
$("#overallfoot").load("overall_footer.html");
});
</script>
<style>
body {
color: Thistle;
}
</style>
<div id="overallhead"></div>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Creature Paradise</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="container">
<div id="login-form">
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
<div class="col-md-12">
<div class="form-group">
<h2 class="">Login</h2>
</div>
<div class="form-group">
<hr />
</div>
<?php
if ( isset($errMSG) ) {
?>
<div class="form-group">
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <?php echo $errMSG; ?>
</div>
</div>
<?php
}
?>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
<input type="name" name="name" class="form-control" placeholder="Your Username" value="<?php echo $name; ?>" maxlength="40" />
</div>
<span class="text-danger"><?php echo $nameError; ?></span>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input type="password" name="pass" class="form-control" placeholder="Your Password" maxlength="15" />
</div>
<span class="text-danger"><?php echo $passError; ?></span>
</div>
<div class="form-group">
<hr />
</div>
<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-login">Sign In</button>
</div>
<div class="form-group">
<hr />
</div>
<div class="form-group">
Don't have an account? Sign up here!
</div>
</div>
</form>
</div>
</div>
<div id="overallfoot"></div>
</body>
</html>
<?php ob_end_flush(); ?>
Have you do hashing on registration page, too? Because $row['userPass'] will never equal $passwordHash if you have not registration a new account with new hash applied
I am new to web development and want to make a simple login form, although Not sure why my login button is not responding, the user is required to enter their email ans password. once the user enters a password the login button does not work.
<?php
session_start();
if(isset($_POST['submit'])) {
include_once("php/config/database.php");
$Email = strip_tags($_POST['Email']);
$dbPassword = strip_tags($_POST['Password']);
$Email = stripslashes($Email);
$dbPassword = stripslashes($dbPassword);
$Email = mysqli_real_escape_string($conn, $Email);
$dbPassword = mysqli_real_escape_string($conn, $dbPassword);
$dbPassword = md5($dbPassword);
$sql = ("SELECT * FROM 'Users' WHERE Email='$Email' LIMIT 1");
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($query);
$UserID = $row['UserID'];
$dbpass_Password = $row['Password'];
if($dbPassword == $dbpass_Password) {
$_SESSION['Email'] = $Email;
$_SESSION['UserID'] = $UserID;
header("Location: account.php");
}
else
{
echo "You didn't enter the correct details!";
}
}
?>
<html >
<head>
<meta charset="UTF-8">
<title>background</title>
<link rel="stylesheet" href="css/style.css">
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</head>
<body>
<div class="container demo-1">
<div class="content">
<div id="large-header" class="large-header">
<form action="index.php" method="POST>
<div class="box">
<h1 id="logintoregister">Login</h1>
<div class="group show">
<input class="inputMaterial" type="text" name="FirstName" >
<span class="highlight"></span>
<span class="bar"></span>
<label>First Name</label>
</div>
<div class="group show">
<input class="inputMaterial" type="text" name="Surname" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Surname</label>
</div>
<div class="group ">
<input class="inputMaterial" type="email" name="Email" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
<div class="group">
<input class="inputMaterial" type="password" id="password" name="Password" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Password</label>
</div>
<div class="group show">
<input class="inputMaterial" type="password" id="confirm_password" >
<span class="highlight"></span>
<span class="bar"></span>
<label>Confirm Password</label>
</div>
<button id="buttonlogintoregister" type = "submit" name="submit">Login</button>
<p id="plogintoregister">By registering, You accept all terms and conditons </p>
<p id="textchange" onclick="register()"> Sign Up</p>
</form>
<!-- Related demos -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
Your html is broken:
<form action="index.php" method="POST" />
^---
You self-closed the form tag, so EVERY input field on your page is OUTSIDE of your form.
Plus note you have other logic bugs as well:
if($Password == $dbpass_Password) {
^----
$password is an sql-escaped version of the user's PW. If that password naturally contains SQL metacharacters, the password will NOT compare as equal to what comes out of the database. Those escapes are stripped during the DB insert process, and you'll end up doing something like
"Miles O\'Brien" == "Miles O'Brien"
and return a false mismatch.