register page created an linked to db
This commit is contained in:
parent
c274a8bfa5
commit
53dd39f065
31
layout.php
31
layout.php
|
|
@ -1,3 +1,13 @@
|
|||
<?php
|
||||
session_start();
|
||||
if (isset($_SESSION['loggedin'])) {
|
||||
$logButton = 'href="account/logout.php">Logout';
|
||||
}
|
||||
else {
|
||||
$logButton = 'href="account/login.php">Login';
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -6,29 +16,30 @@
|
|||
echo $pageTitle
|
||||
?>
|
||||
</title>
|
||||
<link rel="stylesheet" href="assets/ibuy.css" />
|
||||
<link rel="stylesheet" href="../assets/ibuy.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="index.php"><span class="i">i</span><span class="b">b</span><span class="u">u</span><span class="y">y</span></a></h1>
|
||||
<h1><a href="../index.php"><span class="i">i</span><span class="b">b</span><span class="u">u</span><span class="y">y</span></a></h1>
|
||||
|
||||
<form action="#">
|
||||
<input type="text" name="search" placeholder="Search for anything" />
|
||||
<input type="submit" name="submit" value="Search" />
|
||||
</form>
|
||||
|
||||
</header>
|
||||
|
||||
<nav> <!--TODO: Populate this list from the categories defined by the admins-->
|
||||
<ul>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Home+%26+Garden">Home & Garden</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Electronics">Electronics</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Fashion">Fashion</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Sport">Sport</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Health">Health</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Toys">Toys</a></li>
|
||||
<li><a class="categoryLink" href="index.php?pageHeading=Motors">Motors</a></li>
|
||||
<li><a class="categoryLink" href="categories.php">More</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Home+%26+Garden">Home & Garden</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Electronics">Electronics</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Fashion">Fashion</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Sport">Sport</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Health">Health</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Toys">Toys</a></li>
|
||||
<li><a class="categoryLink" href="../index.php?pageHeading=Motors">Motors</a></li>
|
||||
<li><a class="categoryLink" <?php echo $logButton?></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<img src="../assets/banners/1.jpg" alt="Banner" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
$pageTitle = 'iBuy - Login';
|
||||
$pageContent = '<p>Don\'t have an account?<a href=\'register.php\'>Click here to register</a></p>
|
||||
<h1>Login</h1>
|
||||
<form action="login.php" method="POST">
|
||||
<label>Email</label> <input name="email" type="text" />
|
||||
<label>Password</label> <input name="password" type="text" />
|
||||
<input name="submit" type="submit" value="Submit" />
|
||||
</form>';
|
||||
$stylesheet = '../assets/ibuy.css';
|
||||
require '../../layout.php';
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
if (isset($_POST['submit'])) {
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
|
||||
$values = [
|
||||
'email' => $_POST['email']
|
||||
];
|
||||
$stmt->execute($values);
|
||||
$user = $stmt->fetch();
|
||||
if (password_verify($_POST['password'], $user['password'])) {
|
||||
$_SESSION['loggedin'] = $user['user_id'];
|
||||
echo'<p>Successful login</p>';
|
||||
}
|
||||
else {
|
||||
echo '<p>Unsuccessful Login</p>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
function addUser() {
|
||||
$server = 'mysql';
|
||||
$username = 'student';
|
||||
$password = 'student';
|
||||
$schema = 'ibuy';
|
||||
$pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);
|
||||
|
||||
$stmt = $pdo->prepare('INSERT INTO users (first_name, last_name, email, password)
|
||||
VALUES (:first_name, :last_name, :email, :password)');
|
||||
$values = [
|
||||
'first_name' => $_POST['first_name'],
|
||||
'last_name' => $_POST['last_name'],
|
||||
'email' => $_POST['email'],
|
||||
'password' => password_hash($_POST['password'], PASSWORD_DEFAULT)
|
||||
];
|
||||
$stmt->execute($values);
|
||||
}
|
||||
|
||||
$pageTitle = 'iBuy - Register';
|
||||
$pageContent = '<p>Already have an account?<a href=\'login.php\'>Click here to Login</a></p>
|
||||
<h1>Register</h1>
|
||||
<form action="register.php" method="POST">
|
||||
<label>First Name</label> <input name="first_name" type="text" />
|
||||
<label>Last Name</label> <input name="last_name" type="text" />
|
||||
<label>Email</label> <input name="email" type="text" />
|
||||
<label>Password</label> <input name="password" type="text" />
|
||||
<input name="submit" type="submit" value="Submit" />
|
||||
</form>';
|
||||
require '../../layout.php';
|
||||
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
addUser();
|
||||
echo '<p>Successful account creation</p>';
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue