<?php session_start();
define('HOST','localhost');
define('DBUSERNAME','root');
define('DBPASSWORD','');
define('DBNAME','subbusir');
define('AVAILABLE','1001');
define('DELETED','1000');
function get_connection(){
$con = mysqli_connect(HOST,DBUSERNAME,DBPASSWORD,DBNAME);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
return $con;
}
function user_validation($username, $password){
$con = get_connection();
$username = mysqli_real_escape_string($con, $username);
$password = mysqli_real_escape_string($con, $password);
$sql = "SELECT password from users where name='$username'";
$result = $con->query($sql);
if($result->num_rows){
$validated_password = mysqli_fetch_object($result);
if($validated_password->password!=$password){
die("Invalid password");
}
$sql2 = "SELECT name, status from users where name='$username' and password='$validated_password->password'";
$result2 = $con->query($sql2);
if($result2->num_rows){
$status = mysqli_fetch_object($result2);
if($status->status==AVAILABLE){
$_SESSION['login']=true;
$_SESSION['username']=$result2->name;
echo "<script>location.href='welcome.php'</script>";
}else{
echo "Please confirm your mail..";
}
}else{
echo "Invalid password..";
}
}else{
echo "Account doesn't exists..";
}
}
if(isset($_POST['Login'])){
if(empty($_POST['username']) && empty($_POST['password'])){
echo("Please enter username and password");
}else if(empty($_POST['username'])){
echo("Please enter username");
}else if(empty($_POST['password'])){
echo("Please enter password");
}else{
user_validation(trim($_POST['username']),trim($_POST['password']));
}
}
?>
<form method="post" action="">
<input name="username">
<input type="password" name="password" />
<input type="submit" name="Login" value="Login"/>
</form>
define('HOST','localhost');
define('DBUSERNAME','root');
define('DBPASSWORD','');
define('DBNAME','subbusir');
define('AVAILABLE','1001');
define('DELETED','1000');
function get_connection(){
$con = mysqli_connect(HOST,DBUSERNAME,DBPASSWORD,DBNAME);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
return $con;
}
function user_validation($username, $password){
$con = get_connection();
$username = mysqli_real_escape_string($con, $username);
$password = mysqli_real_escape_string($con, $password);
$sql = "SELECT password from users where name='$username'";
$result = $con->query($sql);
if($result->num_rows){
$validated_password = mysqli_fetch_object($result);
if($validated_password->password!=$password){
die("Invalid password");
}
$sql2 = "SELECT name, status from users where name='$username' and password='$validated_password->password'";
$result2 = $con->query($sql2);
if($result2->num_rows){
$status = mysqli_fetch_object($result2);
if($status->status==AVAILABLE){
$_SESSION['login']=true;
$_SESSION['username']=$result2->name;
echo "<script>location.href='welcome.php'</script>";
}else{
echo "Please confirm your mail..";
}
}else{
echo "Invalid password..";
}
}else{
echo "Account doesn't exists..";
}
}
if(isset($_POST['Login'])){
if(empty($_POST['username']) && empty($_POST['password'])){
echo("Please enter username and password");
}else if(empty($_POST['username'])){
echo("Please enter username");
}else if(empty($_POST['password'])){
echo("Please enter password");
}else{
user_validation(trim($_POST['username']),trim($_POST['password']));
}
}
?>
<form method="post" action="">
<input name="username">
<input type="password" name="password" />
<input type="submit" name="Login" value="Login"/>
</form>
0 comments:
Post a Comment