1 | <?php
|
---|
2 |
|
---|
3 | session_start();
|
---|
4 | if(!isset($_SESSION['userid'])) {
|
---|
5 | header("Location: ./Sign&Log.php");
|
---|
6 | }
|
---|
7 |
|
---|
8 | require './connect.php';
|
---|
9 |
|
---|
10 |
|
---|
11 | if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
---|
12 |
|
---|
13 | $sql = "UPDATE users SET username = :username, firstname = :firstname, lastname = :lastname, phone= :phone, address = :address WHERE userid = :userid";
|
---|
14 | $stmt = $conn->prepare($sql);
|
---|
15 | $stmt->bindParam(':username', $_POST['username'], PDO::PARAM_STR);
|
---|
16 | $stmt->bindParam(':firstname', $_POST['firstName'], PDO::PARAM_STR);
|
---|
17 | $stmt->bindParam(':lastname', $_POST['lastName'], PDO::PARAM_STR);
|
---|
18 | $stmt->bindParam(':phone', $_POST['phone'], PDO::PARAM_STR);
|
---|
19 | $stmt->bindParam(':address', $_POST['address'], PDO::PARAM_STR);
|
---|
20 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
21 | $stmt->execute();
|
---|
22 |
|
---|
23 | header('location: ./Profile.php');
|
---|
24 | die();
|
---|
25 |
|
---|
26 | }
|
---|
27 |
|
---|
28 | $sql = "SELECT users.*, member.* FROM users INNER JOIN member ON member.memberid = users.userid WHERE memberid = :userid";
|
---|
29 | $stmt = $conn->prepare($sql);
|
---|
30 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
31 | $stmt->execute();
|
---|
32 |
|
---|
33 |
|
---|
34 | if($stmt->rowCount() == 0) {
|
---|
35 | $sql = "SELECT * FROM users WHERE userid = :userid";
|
---|
36 | $stmt = $conn->prepare($sql);
|
---|
37 | $stmt->bindParam(':userid', $_SESSION['userid'], PDO::PARAM_INT);
|
---|
38 | $stmt->execute();
|
---|
39 | $users = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
40 |
|
---|
41 | $users['address'] = "";
|
---|
42 | $users['phone'] = "";
|
---|
43 | $users['firstname'] = "";
|
---|
44 | $users['lastname'] = "";
|
---|
45 | }
|
---|
46 | else {
|
---|
47 | $users = $stmt->fetch(PDO::FETCH_ASSOC);
|
---|
48 | }
|
---|
49 |
|
---|
50 | ?>
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | <!DOCTYPE html>
|
---|
55 | <html lang="en">
|
---|
56 | <head>
|
---|
57 | <meta charset="UTF-8">
|
---|
58 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
---|
59 | <title>Edit Profile</title>
|
---|
60 | <link rel="stylesheet" href="CSS/EditProfile.css">
|
---|
61 | </head>
|
---|
62 | <body>
|
---|
63 | <div class="container">
|
---|
64 |
|
---|
65 | <h1>Edit Profile</h1>
|
---|
66 | <form action="./EditProfile.php" method="POST">
|
---|
67 | <div class="form-group">
|
---|
68 | <label for="username">Username</label>
|
---|
69 | <input type="text" id="username" name="username" required value="<?php echo $users['username'] ?>">
|
---|
70 | </div>
|
---|
71 |
|
---|
72 | <div class="form-group">
|
---|
73 | <label for="firstName">First Name</label>
|
---|
74 | <input type="text" id="firstName" name="firstName" required value="<?php
|
---|
75 | echo $users['firstname'];
|
---|
76 | ?>">
|
---|
77 | </div>
|
---|
78 |
|
---|
79 | <div class="form-group">
|
---|
80 | <label for="lastName">Last Name</label>
|
---|
81 | <input type="text" id="lastName" name="lastName" required value="<?php echo $users['lastname'] ?>">
|
---|
82 | </div>
|
---|
83 |
|
---|
84 | <div class="form-group">
|
---|
85 | <label for="phone">Phone Number</label>
|
---|
86 | <input type="tel" id="phone" name="phone" required value="<?php echo $users['phone'] ?>">
|
---|
87 | </div>
|
---|
88 |
|
---|
89 | <div class="form-group">
|
---|
90 | <label for="address">Address</label>
|
---|
91 | <input type="text" id="address" name="address" required value="<?php echo $users['address'] ?>">
|
---|
92 | </div>
|
---|
93 |
|
---|
94 | <div class="button-group">
|
---|
95 | <button type="button" class="btn btn-secondary" onclick="window.history.back()">Cancel</button>
|
---|
96 | <button type="submit" class="btn">Save Changes</button>
|
---|
97 | </div>
|
---|
98 | </form>
|
---|
99 | </div>
|
---|
100 | </body>
|
---|
101 | </html> |
---|