move login.php to the bottom

This commit is contained in:
Andreas Zweili 2017-02-06 19:37:20 +01:00
parent 41934482a6
commit 613cc9bc3c
2 changed files with 3 additions and 59 deletions

View File

@ -1,55 +0,0 @@
<?php
require('db.php');
session_start();
// If form submitted, insert values into the database.
function login()
{
if (isset($_POST['username'])) {
global $db_connection;
// removes backslashes
$username = stripslashes($_REQUEST['username']);
//escapes special characters in a string
$username = mysqli_real_escape_string($db_connection,$username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($db_connection,$password);
//Checking is user existing in the database or not
$query = "SELECT * FROM `users` WHERE username='$username'
and password='".md5($password)."'";
$result = mysqli_query($db_connection,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if ($rows==1) {
$_SESSION['username'] = $username;
// Redirect user to home.php
header("Location: ./home.php");
} else {
echo "<div class='form'>
<h3>Username/password is incorrect.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
}
}
}
// If form submitted, insert values into the database.
function register()
{
if (isset($_REQUEST['username'])) {
// removes backslashes
$username = stripslashes($_REQUEST['username']);
//escapes special characters in a string
$username = mysqli_real_escape_string($db_connection,$username);
$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($db_connection,$email);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($db_connection,$password);
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into `users` (username, password, email, trn_date)
VALUES ('$username', '".md5($password)."',
'$email', '$trn_date')";
$result = mysqli_query($db_connection,$query);
if ($result) {
echo "<div class='form'>
<h3>You are registered successfully.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
}
}
}
?>

View File

@ -1,7 +1,3 @@
<?php
include 'functions.php';
login();
?>
<!DOCTYPE html>
<html>
<head>
@ -25,6 +21,9 @@ login();
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input name="submit" type="submit"/>
<?php
include 'login.php';
?>
</form>
<p>Not registered yet? <a href='registrationindex.php'>Register Here</a></p>
</div>