-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewKontakt.php
147 lines (139 loc) · 3.95 KB
/
newKontakt.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
// This immediately jumps to "contact created," and doesn't
// present the form. I think you need some kind of flag
// that says whether the form has been submitted, not one
// that checks one of the field variables. See how Nixon does this.
require_once 'header.php';
// initialize the variables
$first = $middle = $last = $phone_1 = $phone_2 =
$street_1 = $street_2 = $city = $state = $zip =
$notes = $created = '';
// query generated by the form entry
$queryString = 'INSERT INTO contacts
( user, first, middle, last, phone_1, phone_2,
street_1, street_2, city, state, zip, notes)
VALUES
(:user,:first,:middle,:last,:phone_1,:phone_2,
:street_1,:street_2,:city,:state,:zip,:notes)';
// assigning form entries to the variables
$user = $_SESSION['user'];
$first = $_POST['first'];
$middle = $_POST['middle'];
$last = $_POST['last'];
$phone_1 = $_POST['phone_1'];
$phone_2 = $_POST['phone_2'];
$street_1 = $_POST['street_1'];
$street_2 = $_POST['street_2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$notes = $_POST['notes'];
// execute the database query
// put the result into $query
if ( $last == '' ) {
echo "Please enter new contact's information<br>";
echo <<<_END
<form method='post' action='newKontakt.php'>
<table class='contact'>
<tr>
<td>First Name</td>
<td><input class='field' type='text' maxlength='16'
name='first'>
</td>
</tr>
<tr>
<td>Middle Name</td>
<td><input class='field' type='text' maxlength='16'
name='middle'>
</td>
</tr>
<tr>
<td>Last Name</td>
<td><input class='field' type='text' maxlength='16'
name='last'>
</td>
</tr>
<tr>
<td>Phone Number</td>
<td><input class='field' type='text' maxlength='10'
name='phone_1'>
</td>
</tr>
<tr>
<td>Alternate Phone</td>
<td><input class='field' type='text' maxlength='10'
name='phone_2'>
</td>
</tr>
<tr>
<td>Address</td>
<td><input class='field' type='text' maxlength='16'
name='street_1'>
</td>
</tr>
<tr>
<td>Apartment, etc.</td>
<td><input class='field' type='text' maxlength='16'
name='street_2'>
</td>
</tr>
<tr>
<td>City</td>
<td><input class='field' type='text' maxlength='16'
name='city'>
</td>
</tr>
<tr>
<td>State</td>
<td><input class='field' type='text' maxlength='2'
name='state'>
</td>
</tr>
<tr>
<td>Zipcode</td>
<td><input class='field' type='text' maxlength='16'
name='zip'>
</td>
</tr>
<tr>
<td>Notes</td>
<td><textarea class='field' maxlength='4096'
name='notes'></textarea>
</td>
</tr>
<tr>
<td><input type='submit'
value='Create Contact'>
</td>
</tr>
</table>
</form>
_END;
}
else {
try {
$query = $konnection->prepare($queryString);
$query->bindParam('user', $user, PDO::PARAM_INT);
$query->bindParam('first', $first, PDO::PARAM_INT);
$query->bindParam('middle', $middle, PDO::PARAM_INT);
$query->bindParam('last', $last, PDO::PARAM_INT);
$query->bindParam('phone_1', $phone_1, PDO::PARAM_INT);
$query->bindParam('phone_2', $phone_2, PDO::PARAM_INT);
$query->bindParam('street_1', $street_1, PDO::PARAM_INT);
$query->bindParam('street_2', $street_2, PDO::PARAM_INT);
$query->bindParam('city', $city, PDO::PARAM_INT);
$query->bindParam('state', $state, PDO::PARAM_INT);
$query->bindParam('zip', $zip, PDO::PARAM_INT);
$query->bindParam('notes', $notes, PDO::PARAM_INT);
$query->execute();
echo "<div class='main'>" .
"New Contact Created<br>" .
"Click <a href='view.php'>here</a> " .
"to return to your contacts list." .
"</div>";
}
catch( PDOException $e ) {
echo $sql."<br>".$e->getMessage();
}
} // end else
?>