<?php
include 'mysqlHandler.php';
openConnection();
$u = str_replace(" ", "", $_POST['username']);
$u = mysql_real_escape_string($u);
$p = $_POST['password'];
if (strlen($p) < 6) {
header("Location:createAccount.php?bad_password=1");
} else if ($_POST['password'] != $_POST['password2']) {
header("Location:createAccount.php?bad_password=1");
} else if (empty($u)) {
header("Location:createAccount.php?user_exists=1");
} else {
$p = hashPassword($_POST['password']);
$result = executeQuery("insert into user (username, password) values ('" . $u . "', '" . $p . "')");
if ($result) {
include 't/headSectionUnclosed.php';
echo '</head><body>';
include 't/userBar.php';
echo '<h1>Successfully created account</h1>';
echo '<h2>Welcome aboard, <em>' .$u . '!</em></h2>';
echo '<a href="index.php" id="button-link">Log in →</a>';
echo '</body></html>';
} else {
header("Location:createAccount.php?user_exists=1");
}
}
closeConnection();
?>