-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_basic.php
executable file
·241 lines (184 loc) · 6.93 KB
/
edit_basic.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/*
Allows user to edit specific entry in database
*/
session_start();
// creates the edit record form
// since this form is used multiple times in this file, made it for easily reuse!
function renderForm($id, $name, $dept, $title, $office, $phone, $email, $photo, $website, $resume, $scholar, $edu, $error)
{
?>
<!DOCTYPE HTML>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<head>
<title>Edit Basic Information</title>
</head>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<body style="margin:10%; margin-left:20%; margin-right:20%">
<div class="w3-card-4 w3-large">
<div class="w3-container w3-light-green">
<h2>Edit Basic Information</h2>
</div>
<form action="" method="post" class="w3-container">
<input class="w3-input w3-border" type="hidden" name="id" value="<?php echo $id; ?>"/>
<input class="w3-input w3-border" type="hidden" name="name" value="<?php echo $name; ?>"/>
<input class="w3-input w3-border" type="hidden" name="dept" value="<?php echo $dept; ?>"/>
<p>
<label class="w3-label"><strong>ID* :</strong></label> <?php echo $id; ?>
</p>
<p>
<label class="w3-label"><strong>Name* :</strong></label> <?php echo $name; ?>
</p>
<p>
<label class="w3-label"><strong>Department* :</strong></label>
<select class="w3-select w3-border" type="text" name="dept">
<option value="" disabled selected>Choose the department</option>
<option value="Electrical and Computer Engineering">Electrical and Computer Engineering</option>
<option value="Computer Science and Engineering">Computer Science and Engineering</option>
<option value="Material Science and Engineering">Material Science and Engineering</option>
<option value="Aerospace Engineering">Aerospace Engineering</option>
<option value="Biomedical Engineering">Biomedical Engineering</option>
<option value="Chemial Engineering">Chemial Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Engineering Technology and Industrial">Engineering Technology and Industrial</option>
<option value="Industrial and Systems Engineering">Industrial and Systems Engineering</option>
<option value="Nuclear Engineering">Nuclear Engineering</option>
<option value="Ocean Engineering">Ocean Engineering</option>
<option value="Petroleum Engineering">Petroleum Engineering</option>
</select>
<p>
<label class="w3-label">Title:</label>
<input class="w3-input w3-border" type="text" name="title" value="<?php echo $title; ?>"/>
</p>
<p>
<label class="w3-label">Office:</label>
<input class="w3-input w3-border" type="text" name="office" value="<?php echo $office; ?>"/>
</p>
<p>
<label class="w3-label">Phone:</label>
<input class="w3-input w3-border" type="text" name="phone" value="<?php echo $phone; ?>"/>
</p>
<p>
<label class="w3-label">Email: *</label>
<input class="w3-input w3-border" type="text" name="email" value="<?php echo $email; ?>"/>
</p>
<p>
<label class="w3-label">Photo(hyperlink):</label>
<input class="w3-input w3-border" type="text" name="photo" value="<?php echo $photo; ?>"/>
</p>
<p>
<label class="w3-label">Website:</label>
<input class="w3-input w3-border" type="text" name="website" value="<?php echo $website; ?>"/>
</p>
<p>
<label class="w3-label">Resume(hyperlink):</label>
<input class="w3-input w3-border" type="text" name="resume" value="<?php echo $resume; ?>"/>
</p>
<p>
<label class="w3-label">Google Scholar Page:</label>
<input class="w3-input w3-border" type="text" name="scholar" value="<?php echo $scholar; ?>"/>
</p>
<p>
<label class="w3-label">Education:</label>
<input class="w3-input w3-border" type="text" name="edu" value="<?php echo $edu; ?>"/>
</p>
<p><strong>* Required</strong></p>
<input class="w3-btn-block w3-green" type="submit" name="submit" value="Submit">
<div class="w3-panel w3-padding-4"></div>
</div>
</div>
</form>
</body>
</html>
<?php
}
// connect to the database
include('connect_db.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$name = $_POST['name'];
$title = $_POST['title'];
$office = $_POST['office'];
$phone = $_POST['phone'];
$photo = $_POST['photo'];
$website= $_POST['website'];
$resume = $_POST['resume'];
$scholar= $_POST['scholar'];
$edu = $_POST['edu'];
$email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
$dept = mysql_real_escape_string(htmlspecialchars($_POST['dept']));
// check that email/dept fields are both filled in
if ($email == '' || $dept == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($id, $name, $dept, $title, $office, $phone, $email, $photo, $website, $resume, $scholar, $edu, $error);
}
else
{
// save the data to the database
$myquery = "UPDATE basic SET name = '$name', dept = '$dept', title = '$title', office = '$office', phone = '$phone', email = '$email', photo = '$photo' WHERE id = '$id'";
mysql_query($myquery)
or die("Cannot process the query : ". $myquery. mysql_error());
$myquery = "UPDATE academic SET name = '$name', website = '$website', resume = '$resume', scholar = '$scholar', email = '$email', education = '$edu' WHERE id = '$id'";
mysql_query($myquery)
or die("Cannot process the query : ". $myquery. mysql_error());
// once saved, redirect back to the view page
header("Location: users_page.php");
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'id' value from the URL (if it exists), making sure that it is valid
if (isset($_GET['id']) && is_numeric($_GET['id']) )
{
// query db
$id = $_GET['id'];
$myquery = "SELECT basic.*, academic.website, academic.resume, academic.scholar, academic.education FROM basic, academic WHERE basic.id = $id AND basic.name = academic.name";
$result = mysql_query($myquery)
or die("Cannot process the query: ".$myquery. mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$name = $row[1];
$dept = $row[2];
$title = $row[3];
$office = $row[4];
$phone = $row[5];
$email = $row[6];
$photo = $row[7];
$website = $row[8];
$resume = $row[9];
$scholar = $row[10];
$edu = $row[11];
// show form
renderForm($id, $name, $dept, $title, $office, $phone, $email, $photo, $website, $resume, $scholar, $edu, '');
}
else
// if no match, display result
{
echo "No matched results for the id: ".$id."!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error! Invalid id : '.$_GET['id'].' !';
}
}
?>