-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofileFunctions.php
More file actions
153 lines (137 loc) · 6.31 KB
/
Copy pathprofileFunctions.php
File metadata and controls
153 lines (137 loc) · 6.31 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?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")
if (isset($_POST['gender']) && isset($_POST['sexpref']) && isset($_POST['age']) && isset($_POST['bio']) && isset($_POST['area']) )
{
$_SESSION['profileCompleted'] = 1;
// echo $_SESSION['profileCompleted'];
try{
$sql = $conn->prepare("INSERT INTO userprofile(gender, sexpref, age, bio, area,userId) VALUES(:gender, :sexpref, :age, :bio, :area, :userId)");
$sql->bindParam(':gender', $_POST['gender']);
$sql->bindParam(':sexpref', $_POST['sexpref']);
$sql->bindParam(':age', $_POST['age']);
$sql->bindParam(':bio', $_POST['bio']);
$sql->bindParam(':area', $_POST['area']);
$sql->bindParam(':userId', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
// echo 'yo';
// var_dump($_SESSION['id']);
// echo 'yo';
if ($_SESSION['profileCompleted'] == 1)
{
try
{
$query = $conn->prepare("UPDATE users SET profileCompleted=:profileCompleted WHERE id=:userid");
$query->bindParam(':profileCompleted', $_SESSION['profileCompleted']);
$query->bindParam(':userid', $_SESSION['id']);
$query->execute();
} catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['food']))
{
try{
$sql = $conn->prepare("INSERT INTO interesttags(interest, userId) VALUES(:food, :userId)");
// var_dump($sql);
// print_r($sql.'yooooo');
$sql->bindParam(':food', $_POST['food']);
$sql->bindParam(':userId', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['books']))
{
try{
$sql = $conn->prepare("INSERT INTO interesttags(interest, userId) VALUES(:books, :userId)");
// var_dump($sql);
// print_r($sql.'yooooo');
$sql->bindParam(':books', $_POST['books']);
$sql->bindParam(':userId', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['travel']))
{
try{
$sql = $conn->prepare("INSERT INTO interesttags(interest, userId) VALUES(:travel, :userId)");
// var_dump($sql);
// print_r($sql.'yooooo');
$sql->bindParam(':travel', $_POST['travel']);
$sql->bindParam(':userId', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
if (isset($_POST['sports']))
{
try{
$sql = $conn->prepare("INSERT INTO interesttags(interest, userId) VALUES(:sports, :userId)");
// var_dump($sql);
// print_r($sql.'yooooo');
$sql->bindParam(':sports', $_POST['sports']);
$sql->bindParam(':userId', $_SESSION['id']);
$sql->execute();
}catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
}
////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////
$firstPic = 0;
if (count($_FILES) > 0) {
if (is_uploaded_file($_FILES['userImage']['tmp_name'][0])) {
//require_once "../Matcha-2020-master/config/database.php";
foreach ($_FILES['userImage']['tmp_name'] as $key => $value)
{
// echo $value;
$imgData = addslashes(file_get_contents($value));
$imageProperties = getimageSize($value);
$sql = "INSERT INTO user_images(imageType ,imageData , users_id) VALUES('{$imageProperties['mime']}', '{$imgData}', {$_SESSION['id']})";
if ($firstPic == 0){
$sql = "INSERT INTO user_images(imageType ,imageData , users_id, profilePicture) VALUES('{$imageProperties['mime']}', '{$imgData}', {$_SESSION['id']}, 1)";
$firstPic++;
}
// $sql = "INSERT INTO user_images(imageType ,imageData , users_id) VALUES('{$imageProperties['mime']}', '{$imgData}', {$_SESSION['id']})";
try{
$current_id = $conn->prepare($sql);
$current_id->execute();
header("Location: home.php");
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
}
}