-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerAccount.php
44 lines (31 loc) · 1.08 KB
/
registerAccount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once './vendor/autoload.php';
session_start();
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
use database\Connection;
try{
$connection = Connection::createConnection();
if(!empty($username) && !empty($email) && !empty($password))
{
$query = '
INSERT INTO users(username, email, password) values(:username, :email, :password)
';
$statement = $connection->prepare($query);
$statement -> bindParam(':username', $username);
$statement -> bindParam(':email', $email);
$statement -> bindParam(':password', $password);
$statement->execute();
$_SESSION['user'] = $username;
$_SESSION['authenticated'] = true;
header("location: home.php");
}
else{
throw new Exception("invalid values");
}
}
catch(Exception $error)
{
header('location: createAccount.php?error=500&message=');
}