-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofilePHP.php
91 lines (76 loc) · 2.22 KB
/
profilePHP.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
<?php
session_set_cookie_params(0);
session_start();
if(!isset($_SESSION[userId])) {
header("Location: ./signin.php");
exit();
}
$username = $_SESSION['username'];
if(isset($_POST['profile-submit'])) {
$host = "localhost";
$user = "first_year";
$database = "first_year";
$passwd = "first_year";
$con = new mysqli($host, $user, $passwd, $database);
if($con->connect_errno) {
die("Can not connect: ".$con->connect_error);
}
$table = "mihir_users";
$email = $_POST['email'];
$sex = $_POST['sex'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
if(empty($email) || empty($sex) || empty($fname) || empty($lname) || empty($phone)) {
header("Location: ./profile.php?error=emptyfields");
exit();
}
if(getimagesize($_FILES['image']['tmp_name']) == FALSE) {
$name = addslashes($_FILES['image']['name']);
$image = base64_encode(file_get_contents(addslashes($_FILES['image']['tmp_name'])));
$sql = "UPDATE $table
SET
email = '$email',
phone = '$phone',
sex = '$sex',
fname = '$fname',
lname = '$lname'
WHERE username = '$username'
";
if($con->query($sql) === TRUE) {
header("Location: ./mainapp.php");
exit();
}
else {
header("Location: ./profile.php?error=sqlerror");
exit();
}
} else {
$name = addslashes($_FILES['image']['name']);
$image = base64_encode(file_get_contents(addslashes($_FILES['image']['tmp_name'])));
$sql = "UPDATE $table
SET
email = '$email',
phone = '$phone',
sex = '$sex',
photo_name = '$name',
image = '$image',
fname = '$fname',
lname = '$lname'
WHERE username = '$username'
";
if($con->query($sql) === TRUE) {
header("Location: ./mainapp.php");
exit();
}
else {
header("Location: ./profile.php?error=sqlerror");
exit();
}
}
$con->close();
} else {
header("Location: ./profile.php");
exit();
}
?>