-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
49 lines (37 loc) · 1.4 KB
/
test.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
45
46
47
48
49
<?php
function parsedate(string $date) {
return substr($date, -4) . "-" . substr($date, 0,2) . "-" . substr($date, 3,2);
}
$conn = mysqli_connect('localhost', 'root', 'root', 'unity_access');
//check to see if the conn happened
if (mysqli_connect_errno())
{
echo "1: Connection failed";
exit();
}
//get the fields from the form
$username = $_POST["name"];
$datestring = $_POST["dob"];
$dob = parsedate($datestring);
$comments = $_POST["comments"];
//check if name exists
$namecheckquery = "SELECT name FROM subjects WHERE name = '" . $username . "';";
$namecheck = mysqli_query($conn, $namecheckquery) or die("2: Name check query failed");
if (mysqli_num_rows($namecheck) > 0)
{
die("3: Name already exists");
}
$subjectinsertquery = "INSERT INTO subjects (name, dob, comments) VALUES ('" . $username . "','" . $dob . "','" . $comments . "');";
mysqli_query($conn, $subjectinsertquery) or die("4: Insert into DB failed.");
//want to return the user's id for the next part of the test
$idcheckquery = "SELECT id FROM subjects WHERE name = '" . $username . "';";
$idcheck = mysqli_query($conn, $idcheckquery) or die("5: Id check query failed");
while($row = mysqli_fetch_assoc($idcheck)) {
die("0:" . $row["id"]);
}
//if (mysqli_num_rows($idcheck) > 0)
//{
//die("0: Id:");
//}
die("0: Sucessfully inserted " . $username);
?>