For an exercise I am trying to create a login page. This is my first experience with php. I have been looking at many guides and looked at many questions from stackoverflow. So this is what I came up with.(I am using XAMPP for the Database)
Folder php: login.php, session.php, welcome.php, Connection.php
Folder pages: login.html
DB Name: leftoveryouth
Table Name: clients
Colums:id, FirstName, lastname, birthdate, street, streetnr, city, plz, username, email, Password
Relevant HTML Code:
<div class="placeholder">
<h1 class="logo"><a href="/index.html"class="alogo">Leftover Youth</a></h1>
<img class="logoo" src="../img/logoo.png" alt="firstimage">
<form class="form" action = "" method = "post">
<hr class="verticalline">
<input id="email" type="text" value="Email@address.com"
onblur="this.value'Email@address.com:this.value;"
onfocus="this.select()"
onclick="if (this.value=='Email@address.com'){this.value=''; this.type='Email@address.com'}"/>
<br>
<br>
<br>
<input id="password" value="Password"
onblur="this.value'Password:this.value;"
onfocus="this.select()"
onclick="if (this.value=='Password'){this.value=''; this.type='password'}"/>
<br>
<br>
<br>
<input id="button" type="submit" value="Log In">
<div class="links">
<a href="forgotpd.html" class="forpassword">Forgot Password?</a>
<a href="register.html" class="wannaregister">Create an Account?</a>
</div>
</form>
</div>
connection.php:
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'leftoveryouth');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
session.php:
<?php
include('connection.php');
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysqli_query($db,"select username from clients where username = '$user_check' ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session = $row['username'];
if(!isset($_SESSION['login_user'])){
header("location:login.php");
}
?>
login.php:
<?php
include("connection.php");
include("/pages/login.html");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT id FROM clients WHERE username = '$myusername' and password = '$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
welcome.php:
<?php
include('session.php');
?>
<html>
<head>
<title>Welcome </title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
<h2><a href = "logout.php">Sign Out</a></h2>
</body>
</html>
I always get this Error code:
Cannot POST /pages/login.html
I don't care about Security at the moment. I will care about that after the basic login works:) So does somebody know what I have done wrong?
-------------EDIT:-------------------- Errors:Warning: include(/left_over_youth_website/php/connection.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 2
Warning: include(): Failed opening '/left_over_youth_website/php/connection.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 2
Warning: include(/left_over_youth_website/pages/login.html): failed to open stream: No such file or directory in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 3
Warning: include(): Failed opening '/left_over_youth_website/pages/login.html' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 3
Notice: Undefined variable: db in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 9
Notice: Undefined index: username in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 9
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 9
Notice: Undefined variable: db in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 10
Notice: Undefined index: password in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 10
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 10
Notice: Undefined variable: db in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 13
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 13
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 14
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\Left_over_youth_website\php\logins.php on line 17