-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditProfile.php
More file actions
79 lines (66 loc) · 2.78 KB
/
editProfile.php
File metadata and controls
79 lines (66 loc) · 2.78 KB
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
<?php
session_start();
if (!isset($_SESSION["currentUser"])) {
header("Location : login.php");
die();
}
$db = mysqli_connect('localhost', 'root', '') or die('Unable to connect. Check your connection parameters.');
mysqli_select_db($db, 'projectSite') or die(mysqli_error($db));
$currentUserID = $_SESSION["currentUser"];
$userData = mysqli_fetch_assoc(mysqli_query($db, "SELECT * FROM student WHERE id = '$currentUserID'"));
$oldFirstName = $userData['firstName'];
$oldLastName = $userData['lastName'];
$oldEmail = $userData['email'];
?>
<html>
<head>
<link rel="stylesheet" href="css/form.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bodyMain.css">
</head>
<body>
<div class="bodyMain">
<h1>Update Profile</h1>
<form action="" method="post" id="signupForm">
<div class="formBox">
<fieldset>
<legend>Personal Info: </legend>
<!-- https://stackoverflow.com/questions/20589723/populate-html-form-from-database: Populating form from database -->
<label for="firstName">First Name</label>
<input type="text" maxlength="255" name="firstName" value="<?php echo $oldFirstName ?>" required>
<br>
<label for="lastName">Last Name</label>
<input type="text" maxlength="255" name="lastName" value="<?php echo $oldLastName ?>" id="lastName" required>
<br>
<label for="email">Email:</label>
<input type="email" name="email" id="email" value="<?php echo $oldEmail ?>">
</fieldset>
<button type="submit" id="submitButton">Update Profile!</button>
</div>
</form>
</div>
</body>
<?php
if ($_SERVER["REQUEST_METHOD"] == 'POST') {
$inputFirstName = $_POST["firstName"];
$inputLastName = $_POST["lastName"];
$inputEmail = $_POST["email"];
//https://www.w3schools.com/sql/sql_update.asp
if (trim($inputFirstName) != '') {
$updateQuery = "UPDATE student SET firstName= '$inputFirstName' where id = $currentUserID ";
mysqli_query($db, $updateQuery) or die(mysqli_error($db));
}
if (trim($inputLastName) != '') {
$updateQuery = "UPDATE student SET lastName= '$inputLastName'where id = $currentUserID ";
mysqli_query($db, $updateQuery) or die(mysqli_error($db));
}
if (trim($inputEmail) != '') {
echo "<script>console.log('changed email to : '$inputEmail'')</script>";
$updateQuery = "UPDATE student SET email= '$inputEmail'where id = $currentUserID";
mysqli_query($db, $updateQuery) or die(mysqli_error($db));
}
header("Location: homepage.php");
die();
}
?>
</html>