-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateUser.php
More file actions
40 lines (37 loc) · 1.03 KB
/
createUser.php
File metadata and controls
40 lines (37 loc) · 1.03 KB
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
<?php
// This file adds new users to the database
if (isset($_POST['userSignIn']) && isset($_POST['passSignIn']) && $_POST['passSignIn'] === $_POST['confirmSignIn'])
{
//Import config files for the database. Change if needed
require "config.php";
try
{
$connection = new PDO($dsn, $username, $password, $options);
//Define array from send data
$new_user = array(
"username" => $_POST['userSignIn'],
"password" => $_POST['passSignIn'],
"email" => $_POST['emailSignIn'],
);
//var to add all data into the right rows
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"users",
implode(", ", array_keys($new_user)),
":" . implode(", :", array_keys($new_user))
);
//execute the write to the database process
$statement = $connection->prepare($sql);
$statement->execute($new_user);
echo 'Successfully added';
}
//Error message in case of errors
catch(PDOException $error)
{
echo $sql . "<br>" . $error->getMessage();
}
}
else{
echo "Please enter all information correctly";
}
?>