-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
284 lines (281 loc) · 8.65 KB
/
functions.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
function mysqlexec($sql){
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="mohit"; // Mysql password
$db_name="matrimony"; // Database name
// Connect to server and select databse.
$conn=mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db($conn,"$db_name")or die("cannot select DB");
if($result = mysqli_query($conn, $sql)){
return $result;
}
else{
echo mysqli_error($conn);
}
}
function searchid(){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$profid=$_POST['profid'];
$sql="SELECT * FROM customer WHERE id=$profid";
$result = mysqlexec($sql);
return $result;
}
}
function search(){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$agemin=$_POST['agemin'];
$agemax=$_POST['agemax'];
$maritalstatus=$_POST['maritalstatus'];
$country=$_POST['country'];
$state=$_POST['state'];
$religion=$_POST['religion'];
$mothertounge=$_POST['mothertounge'];
$sex = $_POST['sex'];
$sql="SELECT * FROM customer WHERE
sex='$sex'
AND age>='$agemin'
AND age<='$agemax'
AND maritalstatus = '$maritalstatus'
AND country = '$country'
AND state = '$state'
AND religion = '$religion'
AND mothertounge = '$mothertounge'
";
$result = mysqlexec($sql);
return $result;
}
}
function writepartnerprefs($id){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$agemin=$_POST['agemin'];
$agemax=$_POST['agemax'];
$maritalstatus=$_POST['maritalstatus'];
$complexion=$_POST['colour'];
$height=$_POST['height'];
$diet=$_POST['diet'];
$religion=$_POST['religion'];
$caste=$_POST['caste'];
$mothertounge=$_POST['mothertounge'];
$education=$_POST['education'];
$occupation=$_POST['occupation'];
$country=$_POST['country'];
$descr=$_POST['descr'];
$sql = "UPDATE
partnerprefs
SET
agemin = '$agemin',
agemax='$agemax',
maritalstatus = '$maritalstatus',
complexion = '$complexion',
height = '$height',
diet = '$diet',
religion='$religion',
caste = '$caste',
mothertounge = '$mothertounge',
education='$education',
descr = '$descr',
occupation = '$occupation',
country = '$country'
WHERE
custId = '$id'";
$result = mysqlexec($sql);
if ($result) {
echo "<script>alert(\"Successfully updated Partner Preference\")</script>";
echo "<script> window.location=\"userhome.php?id=$id\"</script>";
}
else{
echo "Error";
}
}
}
function register(){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$uname=$_POST['name'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$dob=$year ."-" . $month . "-" .$day ;
$gender=$_POST['gender'];
require_once("includes/dbconn.php");
$sql = "INSERT
INTO
users
( profilestat, username, password, email, dateofbirth, gender, userlevel)
VALUES
(0, '$uname', '$pass', '$email', '$dob', '$gender', 0)";
if (mysqli_query($conn,$sql)) {
echo "Successfully Registered";
echo "<a href=\"login.php\">";
echo "Login to your account";
echo "</a>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
function isloggedin(){
if(!isset($_SESSION['id'])){
return false;
}
else{
return true;
}
}
function processprofile_form($id){
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$sex=$_POST['sex'];
$email=$_POST['email'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$dob=$year ."-" . $month . "-" .$day ;
$religion=$_POST['religion'];
$caste = $_POST['caste'];
$subcaste=$_POST['subcaste'];
$country = $_POST['country'];
$state=$_POST['state'];
$district=$_POST['district'];
$age=$_POST['age'];
$maritalstatus=$_POST['maritalstatus'];
$profileby=$_POST['profileby'];
$education=$_POST['education'];
$edudescr=$_POST['edudescr'];
$bodytype=$_POST['bodytype'];
$physicalstatus=$_POST['physicalstatus'];
$drink=$_POST['drink'];
$smoke=$_POST['smoke'];
$mothertounge=$_POST['mothertounge'];
$bloodgroup=$_POST['bloodgroup'];
$weight=$_POST['weight'];
$height=$_POST['height'];
$colour=$_POST['colour'];
$diet=$_POST['diet'];
$occupation=$_POST['occupation'];
$occupationdescr=$_POST['occupationdescr'];
$fatheroccupation=$_POST['fatheroccupation'];
$motheroccupation=$_POST['motheroccupation'];
$income=$_POST['income'];
$bros=$_POST['bros'];
$sis=$_POST['sis'];
$aboutme=$_POST['aboutme'];
require_once("includes/dbconn.php");
$sql="SELECT cust_id FROM customer WHERE cust_id=$id";
$result=mysqlexec($sql);
if(mysqli_num_rows($result)>=1){
//there is already a profile in this table for loggedin customer
//update the data
$sql="UPDATE
customer
SET
email = '$email',
age = '$age',
sex = '$sex',
religion = '$religion',
caste = '$caste',
subcaste = '$subcaste',
district = '$district',
state = '$state',
country = '$country',
maritalstatus = '$maritalstatus',
profilecreatedby = '$profileby',
education = '$education',
education_sub = '$edudescr',
firstname = '$fname',
lastname = '$lname',
body_type = '$bodytype',
physical_status = '$physicalstatus',
drink = '$drink',
mothertounge = '$mothertounge',
colour = '$colour',
weight = '$weight',
smoke = '$smoke',
dateofbirth = '$dob',
occupation = '$occupation',
occupation_descr = '$occupationdescr',
annual_income = '$income',
fathers_occupation = '$fatheroccupation',
mothers_occupation = '$motheroccupation',
no_bro = '$bros',
no_sis = '$sis',
aboutme = '$aboutme'
WHERE cust_id=$id; "
;
$result=mysqlexec($sql);
if ($result) {
echo "<script>alert(\"Successfully Updated Profile\")</script>";
echo "<script> window.location=\"userhome.php?id=$id\"</script>";
}
}else{
//Insert the data
$sql = "INSERT
INTO
customer
(id,cust_id, email, age, sex, religion, caste, subcaste, district, state, country, maritalstatus, profilecreatedby, education, education_sub, firstname, lastname, body_type, physical_status, drink, mothertounge, colour, weight, height, blood_group, diet, smoke, dateofbirth, occupation, occupation_descr, annual_income, fathers_occupation, mothers_occupation, no_bro, no_sis, aboutme, profilecreationdate )
VALUES
(NULL,'$id','$email', '$age', '$sex', '$religion', '$caste', '$subcaste', '$district', '$state', '$country', '$maritalstatus', '$profileby', '$education', '$edudescr', '$fname', '$lname', '$bodytype', '$physicalstatus', '$drink', '$mothertounge', '$colour', '$weight', '$height', '$bloodgroup', '$diet', '$smoke', '$dob', '$occupation', '$occupationdescr', '$income', '$fatheroccupation', '$motheroccupation', '$bros', '$sis', '$aboutme', CURDATE())
";
$result=mysqlexec($sql);
//mysqli_query($conn,$sql)
if ($result) {
echo "Successfully Created profile";
echo "<a href=\"userhome.php?id={$id}\">";
echo "Back to home";
echo "</a>";
//creating a slot for partner prefernce table for prefs details with cust id
$sql2="INSERT INTO partnerprefs (id, custId) VALUES('', '$id')";
mysqli_query($conn,$sql2);
$sql2="UPDATE TABLE users SET profilestat=1 WHERE id=$id";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
}
//function for upload photo
function uploadphoto($id){
$target = "profile/". $id ."/";
if (!file_exists($target)) {
mkdir($target, 0777, true);
}
//specifying target for each file
$target1 = $target . basename( $_FILES['pic1']['name']);
$target2 = $target . basename( $_FILES['pic2']['name']);
$target3 = $target . basename( $_FILES['pic3']['name']);
$target4 = $target . basename( $_FILES['pic4']['name']);
// This gets all the other information from the form
$pic1=($_FILES['pic1']['name']);
$pic2=($_FILES['pic2']['name']);
$pic3=($_FILES['pic3']['name']);
$pic4=($_FILES['pic4']['name']);
$sql="SELECT id FROM photos WHERE cust_id = '$id'";
$result = mysqlexec($sql);
//code part to check weather a photo already exists
if(mysqli_num_rows($result) == 0) {
// no photo for curret user, do stuff...
$sql="INSERT INTO photos (id, cust_id, pic1, pic2, pic3, pic4) VALUES (NULL,'$id', '$pic1' ,'$pic2', '$pic3','$pic4')";
// Writes the information to the database
mysqlexec($sql);
} else {
// There is a photo for customer so up
$sql="UPDATE photos SET pic1 = '$pic1', pic2 = '$pic2', pic3 = '$pic3', pic4 = '$pic4' WHERE cust_id=$id";
// Writes the information to the database
mysqlexec($sql);
}
// Writes the photo to the server
if(move_uploaded_file($_FILES['pic1']['tmp_name'], $target1)&&move_uploaded_file($_FILES['pic2']['tmp_name'], $target2)&&move_uploaded_file($_FILES['pic3']['tmp_name'], $target3)&&move_uploaded_file($_FILES['pic4']['tmp_name'], $target4))
{
// Tells you if its all ok
echo "The files has been uploaded, and your information has been added to the directory";
}
else {
// Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
}//end uploadphoto function
?>