<?php
session_start();
$errmsg_arr = array();
$errflag = false;
// configuration
$dbhost = "localhost";
$dbname = "members";
$dbuser = "root";
$dbpass = "";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
// new data
$email = $_POST['uemail'];
$password = $_POST['upassword'];
if($email == '') {
$errmsg_arr[] = 'You must enter your Email';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'You must enter your Password';
$errflag = true;
}
// query
$result = $conn->prepare("SELECT * FROM users WHERE email AND password");
$result->bindParam($email);
$result->bindParam($password);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
if($rows > 0) {
header("location: newfeeds.php");
}
else{
$errmsg_arr[] = 'Email and Password are not found';
$errflag = true;
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
?>
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array ($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
echo '<ul style="padding:0; color:red;">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<form class="pop" method="post" action="login.php">
<p class="login">LOGIN</p>
<div class="form-group">
<div class="left-inner-addon "><i class="fa fa-envelope-o fa-fw"></i>
<input type="email" name="uemail" class="form-control" id="email" placeholder="Email" required>
</div>
</div>
<div class="form-group">
<div class="left-inner-addon"><i class="fa fa-key fa-fw"></i>
<input type="password" name="upassword" class="form-control" id="password" placeholder="Password" required>
</div>
</div>
<p>Forgot Password?</p>
<div class="form-group">
<button class="btn btn-default" role="button" name="login" id="login">LOGIN</button>
</div>
</form>
</div>
</div>
<!-- form-->
CREATE TABLE `users` (
`memberID` int(5) NOT NULL,
`username` varchar(65) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`gender` varchar(200) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
I have seen everywhere have the same issue of login not showing true login or false. I have type all these answers but that didn't work. Mostly register is working awesome with encrypt password and it stored well in the database. About login form, it sound crazy I have been post it so many times and correct it but I want to get the right answer. It should redirect after user logged in to another page and I should know that after user logged it is possible to store in different table in the same database.
EX: for register users (id, username, email, password, gender) and for user_login table (id, email and password). Im new to sql and php and still struggling to get good answers. Please help and use the same variables of what I put in.