-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit-profile-exec.php
73 lines (58 loc) · 1.54 KB
/
edit-profile-exec.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
<?php
//Start session
session_start();
$username=$_SESSION['SESS_MEMBER_ID'];
//Include database connection details
require_once('database.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$college = clean($_POST['college']);
$contact = clean($_POST['contact']);
//Input Validations
if($college == '') {
$errmsg_arr[] = 'College name missing';
$errflag = true;
}
if($contact == '') {
$errmsg_arr[] = 'Contact number missing';
$errflag = true;
}
//Check for contact number
if($contact != '') {
if(!is_numeric($contact))
{
$errmsg_arr[] = 'Check u r Contact number';
$errflag = true;
}
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: edit-profile.php");
exit();
}
//Create INSERT query
$qry = "UPDATE user_login SET contact = '$contact' WHERE member_id ='$username'";
$result = @mysql_query($qry);
$qry = "UPDATE user_login SET college = '$college' WHERE member_id ='$username'";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: profile.php");
exit();
}else {
die("Query failed");
}
?>