-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphandleview.php
More file actions
101 lines (78 loc) · 3.09 KB
/
Copy pathphandleview.php
File metadata and controls
101 lines (78 loc) · 3.09 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
<?php
session_start();
include("connection.php") ;
$errors=array();
if(isset($_POST['delete'])){
$id = $_GET["parent_id"];
$query = mysqli_query($con,"DELETE FROM parent WHERE `parent_id` =$id;");
header("Location:index.php");
}
if(isset($_POST['edit'])){
header("Location:editparent.php");
} /////////////////////////
if(isset($_POST['save'])){
$id = $_GET["parent_id"];
$username = $_POST['parentname'];
$email = $_POST['userEmail'];
$password1 = mysqli_real_escape_string($con , $_POST['userPassword']);
//$password2 = mysqli_real_escape_string($con ,$_POST['repeatedPassword']);
$phone = $_POST['phone'];
$city = $_POST['city'];
$district = $_POST['district'];
$street = $_POST['street'];
$buildingNo = $_POST['BuildingNo'];
// all img info ------
if( isset($_FILES['image'])){
$image=$_FILES['image'];
$imgName=$_FILES['image']['name'];
$imgTmpName=$_FILES['image']['tmp_name'];
$upload_directory="images/"; //to move ir to this file
$TargetPath=time().$imgName;
if(move_uploaded_file($imgTmpName, $upload_directory.$TargetPath)){
//$result = mysqli_query($con, $QueryInsertFile);
}
}// is set
/*if ($password1 !== $password2) {
header("Location: editparent.php?error=Passwords do not match , please try again!");
exit;
array_push($errors , "Passwords do not match");
}*/
//check db for existing parent with the same email
$emailcheck_query = "SELECT * FROM parent WHERE email = '$email' AND parent_id !='$id'";
$result = mysqli_query($con, $emailcheck_query);
if (mysqli_num_rows($result) > 0) {
array_push($errors , "Email already exists");
header("location: editparent.php?error=Email already existed, please try again!");
}
//phone number validation
if(!preg_match('/^[0-9]{10}+$/', $phone)) {
header("Location: editparent.php?error=Phone number is invalid, please try again!");
exit;
array_push($errors , "Phone number is invalid");
}
//email syntax validation
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: editparent.php?error=Invalid Email syntax, please try again!");
exit;
array_push($errors , "Phone number is invalid");
}
//check db for existing parent with the same phone
$phonecheck_query = "SELECT * FROM parent WHERE phoneNo = '$phone'";
$result = mysqli_query($con, $phonecheck_query);
if (mysqli_num_rows($result) > 0) {
array_push($errors , "Phone number already exists");
header("location: editparent.php?error=The phone number already existed, please try again!");
}
if( ! isset($_FILES['image']['name']) || empty($_FILES['image']['name']) ){
$TargetPath="prpic.png";
}
//start updating the profile
if(count($errors)==0){
$password = md5($password1); //encrypting password by using md5()
//update query
$query = "UPDATE parent SET parent_image='$TargetPath' , name='$username' ,email='$email', password='$password',city='$city',district='$district',street='$street',buildingNo='$buildingNo',phoneNo='$phone' WHERE parent_id=$id " ;
mysqli_query($con , $query);
header("Location:parentprofile.php");
}
}
?>