-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddUser.php
More file actions
36 lines (24 loc) · 881 Bytes
/
addUser.php
File metadata and controls
36 lines (24 loc) · 881 Bytes
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
<?php
//See original: https://www.w3schools.com/php/php_mysql_connect.asp
$servername = "localhost";
$username = "root";
$password = "";
$dbName = "chatLog";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbName", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$username = $_GET["username"];
$password = $_GET["password"];
$email = $_GET["email"];
$firstName = $_GET["firstName"];
$lastName = $_GET["lastName"];
$addUser = "INSERT INTO users(username, password, email, firstName, lastName) VALUES ('$username', '$password', '$email', '$firstName', '$lastName')";
//need to use conn -> exec because this sql line doesn't return anything
$conn->exec($addUser);
echo "User added";
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>