-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertValidData.php
86 lines (82 loc) · 2.86 KB
/
insertValidData.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
if ($isValid) {
try {
session_start();
$conn = new PDO("mysql:host=localhost",
"root", "");
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec ("CREATE DATABASE IF NOT EXISTS dogpeople");
$conn->exec ("use dogpeople");
$result = $conn->exec ("CREATE TABLE IF NOT EXISTS registration (
ID INT AUTO_INCREMENT,
userName varchar(255) NOT NULL,
password varchar(255) NOT NULL,
firstName varchar(255) NOT NULL,
lastName varchar(255) NOT NULL,
email varchar(255) NOT NULL,
phone varchar(255) NOT NULL,
birth date,
address1 varchar(255) NOT NULL,
address2 varchar(255) NOT NULL,
city varchar(255) NOT NULL,
state varchar(255) NOT NULL,
zip varchar(255) NOT NULL,
gender varchar(255) NOT NULL,
maritalStatus varchar(255) NOT NULL,
PRIMARY KEY (ID))");
$sql = $conn->prepare("INSERT INTO registration
(userName,
password,
firstName,
lastName,
email,
phone,
birth,
address1,
address2,
city,
state,
zip,
gender,
maritalStatus)
VALUES (:userName,
:password,
:firstName,
:lastName,
:email,
:phone,
:birth,
:address1,
:address2,
:city,
:state,
:zip,
:gender,
:maritalStatus )");
$sql->bindParam(':userName', $regForm["userName"][2]);
$sql->bindParam(':password', $regForm["password"][2]);
$sql->bindParam(':firstName', $regForm["firstName"][2]);
$sql->bindParam(':lastName', $regForm["lastName"][2]);
$sql->bindParam(':email', $regForm["email"][2]);
$sql->bindParam(':phone', $regForm["phone"][2]);
$sql->bindParam(':birth', $regForm["birth"][2]);
$sql->bindParam(':address1', $regForm["address1"][2]);
$sql->bindParam(':address2', $regForm["address2"][2]);
$sql->bindParam(':city', $regForm["city"][2]);
$sql->bindParam(':state', $regForm["state"][2]);
$sql->bindParam(':zip', $regForm["zip"][2]);
$sql->bindParam(':gender', $regForm["gender"][2]);
$sql->bindParam(':maritalStatus', $regForm["maritalStatus"][2]);
$sql->execute();
$last_id = $conn->lastInsertId();
$_SESSION["last_id"] = "$last_id";
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
} finally {
$conn = null;
}
header("Location: confirmation.php");
}
?>