-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentUpdateProfileProcess.php
64 lines (48 loc) · 2.27 KB
/
studentUpdateProfileProcess.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
<?php
session_start();
require "connection.php";
if (isset($_SESSION["student"])) {
$email = $_POST["email"];
$password = $_POST["password"];
if (empty($email)) {
echo "Please enter your email";
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email address";
} else if (strlen($email) > 100) {
echo "Email must be less than 100 characters";
} else if (empty($password)) {
echo "Please enter your password";
} else if (strlen($password) < 5 || strlen($password) > 20) {
echo "Password length must between 5 and 20";
} else if ($email != $_SESSION["student"]["email"]) { //update email & password
$check = Database::search("SELECT * FROM `student` WHERE `email`='" . $email . "' ");
$checkr = $check->num_rows;
if ($checkr == 1) {
echo "This email is already taken!";
} else {
$update = Database::iud("UPDATE `student` SET `email`='" . $email . "' , `password`='" . $password . "' WHERE `s_ad_no`='" . $_SESSION["student"]["s_ad_no"] . "' ");
if (isset($_COOKIE["un"]) && isset($_COOKIE["pw"])) {
setcookie("un", "", -1);
setcookie("pw", "", -1);
}
$newrs = Database::search("SELECT * FROM `student` WHERE `s_ad_no`='" . $_SESSION["student"]["s_ad_no"] . "' ");
$d = $newrs->fetch_assoc();
setcookie("un", $email, time() + (60 * 60 * 24 * 365));
setcookie("pw", $password, time() + (60 * 60 * 24 * 365));
$_SESSION["student"] = $d;
echo "ok";
}
} else { //update only password
$update = Database::iud("UPDATE `student` SET `password`='" . $password . "' WHERE `s_ad_no`='" . $_SESSION["student"]["s_ad_no"] . "' ");
if (isset($_COOKIE["un"]) && isset($_COOKIE["pw"])) {
setcookie("un", "", -1);
setcookie("pw", "", -1);
}
$newrs = Database::search("SELECT * FROM `student` WHERE `s_ad_no`='" . $_SESSION["student"]["s_ad_no"] . "' ");
$d = $newrs->fetch_assoc();
$_SESSION["student"] = $d;
setcookie("un", $email, time() + (60 * 60 * 24 * 365));
setcookie("pw", $password, time() + (60 * 60 * 24 * 365));
echo "ok";
}
}