-
Notifications
You must be signed in to change notification settings - Fork 0
/
editUpdate.php
99 lines (95 loc) · 2.74 KB
/
editUpdate.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
<?php
include("functions.php");
$conn = get_connection_handle();
if(isset($_REQUEST['venue']) && isset($_REQUEST['id'])){
$error = array();
if(is_post("venue")){
$venue = strip_tags($_REQUEST['venue']);
}else{
$error[] = "Venue is required!<br>";
}
if(is_post("end")){
$end = strip_tags($_REQUEST['end']);
}else{
$error[] = "Ending time is required!<br>";
}
if(is_post("start")){
$start = strip_tags($_REQUEST['start']);
}else{
$error[] = "Starting time is required!<br>";
}
if(is_post("day")){
$day = strip_tags($_REQUEST['day']);
}else{
$error[] = "Lesson day is required!<br>";
}
if(is_post("id")){
$id = $_REQUEST['id'];
}
if(!$error){
$stmt = $conn->prepare("update lessons set venue = ?, day = ?,
start = ?, end = ? where id = ?");
$stmt->bind_param("ssssi", $venue, $day, $start,$end, $id);
$stmt->execute();
if($conn->affected_rows == 1){
echo "Update successful";
}else{
echo "Update not successful";
}
}else{
foreach($error as $err){
echo $err;
}
}
}elseif(isset($_REQUEST['name']) && isset($_REQUEST['hostel_id'])){
$error = array();
if(is_post("name")){
$name = strip_tags($_REQUEST['name']);
}else{
$error[] = "Hostel name is required!<br>";
}
if(is_post("contact")){
$contact = strip_tags($_REQUEST['contact']);
}else{
$error[] = "Owner contact is required!<br>";
}
if(is_post("campus")){
$campus = strip_tags($_REQUEST['campus']);
}else{
$error[] = "Campus is required!<br>";
}
if(is_post("rate")){
$rate = strip_tags($_REQUEST['rate']);
}else{
$error[] = "Hostel rate is required!<br>";
}
if(is_post("distance")){
$distance = strip_tags($_REQUEST['distance']);
}else{
$error[] = "Distance to campus is required!<br>";
}
if(is_post("facilities")){
$facilities = strip_tags($_REQUEST['facilities']);
}else{
$error[] = "Hostel facilities cannot be blank!<br>";
}
if(is_post("hostel_id")){
$id = $_REQUEST['hostel_id'];
}
if(!$error){
$stmt = $conn->prepare("update hostels set name = ?, rate = ?,
campus = ?, contact = ?, distance = ?, facilities = ? where id = ?");
$stmt->bind_param("ssssssi", $name, $rate, $campus,$contact,
$distance, $facilities, $id);
$stmt->execute();
if($conn->affected_rows == 1){
echo "Update successful";
}else{
echo "Update not successful";
}
}else{
foreach($error as $err){
echo $err;
}
}
}