Created
September 30, 2015 02:47
-
-
Save AriffAzmi/255b39b412e6ce9ff1dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'dbconfig.php'; | |
if (isset($_POST['btn-login'])) { | |
$user = $_POST['username']; | |
$password = $_POST['password']; | |
if($user == '') { | |
$errmsg_arr[] = 'You must enter your Username'; | |
$errflag = true; | |
} | |
if($password == '') { | |
$errmsg_arr[] = 'You must enter your Password'; | |
$errflag = true; | |
} | |
// query | |
$result = $conn->prepare("SELECT * FROM users WHERE username= :uname AND password= :upass"); | |
$result->bindParam(':uname', $uname); | |
$result->bindParam(':upass', $upass); | |
$result->execute(); | |
$rows = $result->fetch(PDO::FETCH_NUM); | |
if($rows > 0) { | |
$_SESSION['id'] = $rows['id']; | |
header("Location: home.php"); | |
} | |
else{ | |
$errmsg_arr[] = 'Username and Password are not found'; | |
$errflag = true; | |
} | |
if($errflag) { | |
$_SESSION['ERRMSG_ARR'] = $errmsg_arr; | |
session_write_close(); | |
header("location: login.php"); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment