-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_contact_form.php
87 lines (69 loc) · 2.52 KB
/
update_contact_form.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
<?php
require('database.php');
//requested contact id
$contact_id = $_REQUEST['contact_id'];
//get all categoryid and category name
$query = 'SELECT *
FROM categories
ORDER BY categoryID';
$statement = $db->prepare($query);
$statement->execute();
$categories = $statement->fetchAll();
$statement->closeCursor();
//get contact details of requested contact id
$query = "SELECT *
FROM contacts
WHERE contactID = $contact_id";
$statement = $db->prepare($query);
$statement->execute();
$contacts = $statement->fetchAll();
//Edit the contact details
if(count($contacts) > 0)
{
$firstName = $contacts[0]['firstName'];
$lastName = $contacts[0]['lastName'];
$emailAddress = $contacts[0]['emailAddress'];
$phone = $contacts[0]['phone'];
}
?>
<!DOCTYPE html>
<html>
<!-- the head section -->
<head>
<title>Contact Manager</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<!-- the body section -->
<body>
<header><h1>Contact Manager</h1></header>
<main>
<h1>Update Contact</h1>
<form action="update_contact.php" method="post"
id="update_contact_form">
<input type="hidden" name="contact_id" value="<?php echo $contact_id; ?>">
<label>Category:</label>
<select name="category_id">
<?php foreach ($categories as $category) : ?>
<option value="<?php echo $category['categoryID']; ?>">
<?php echo $category['categoryName']; ?>
</option>
<?php endforeach; ?>
</select><br>
<label>First Name:</label>
<input type="text" name="firstName" value="<?php echo htmlspecialchars($firstName); ?>"> <br>
<label>Last Name:</label>
<input type="text" name="lastName" value="<?php echo htmlspecialchars($lastName); ?>"><br>
<label>Email Address:</label>
<input type="text" name="emailAddress" value="<?php echo htmlspecialchars($emailAddress); ?>"><br>
<label>Phone:</label>
<input type="text" name="phone" value="<?php echo htmlspecialchars($phone); ?>"><br>
<label> </label>
<input type="submit" value="Update Contact"><br>
</form>
<p><a href="index.php">View Contact List</a></p>
</main>
<footer>
<p>© <?php echo date("Y"); ?> Contact Manager, Inc.</p>
</footer>
</body>
</html>