-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateProfileFunctions.php
105 lines (88 loc) · 3.94 KB
/
updateProfileFunctions.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$DB_DSN = 'localhost';
$DB_USER = 'root';
$DB_PASSWORD = '';
$DB_NAME = 'matcha2';
//connect to the newly created database
try {
$conn = new PDO("mysql:host=$DB_DSN;dbname=$DB_NAME", $DB_USER, $DB_PASSWORD);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
//INSERT INTO userprofile(gender, sexpref, bio) VALUES("male", "asdasd", "bio")
// var_dump($_SESSION['id']);
if (isset($_POST['username']) && !empty($_POST['username']))
{
try{
$sql = $conn->prepare("UPDATE users SET username=:username WHERE id=:userid");
$sql->bindParam(':username', $_POST['username']);
$sql->bindParam(':userid', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['pass']) && !empty($_POST['pass']))
{
try{
$pass = password_hash(trim($_POST['pass']), PASSWORD_BCRYPT, array('cost' => 5));
$sql = $conn->prepare("UPDATE users SET `password`=:pass WHERE id=:userid");
$sql->bindParam(':pass', $pass, PDO::PARAM_STR, 12);
$sql->bindParam(':userid', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['email']) && !empty($_POST['email']))
{
try{
$sql = $conn->prepare("UPDATE users SET email=:email WHERE id=:userid");
$sql->bindParam(':email', $_POST['email']);
$sql->bindParam(':userid', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['area']) && !empty($_POST['area']))
{
try{
$sql = $conn->prepare("UPDATE userprofile SET area=:area WHERE userId=:userid");
$sql->bindParam(':area', $_POST['area']);
$sql->bindParam(':userid', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['age']) && !empty($_POST['age']))
{
try{
$sql = $conn->prepare("UPDATE userprofile SET age=:age WHERE userId=:userid");
$sql->bindParam(':age', $_POST['age']);
$sql->bindParam(':userid', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
//interests
echo "Profile has been updated";
header("Location: home.php");
?>
<!-- select * from users join interestTags on users.id = interestTags.userId Where interestTags.interest IN('travel', 'food') -->
<!-- SELECT * FROM `likes` WHERE user1 IN(10, 9) AND user2 IN (9, 10) -->