-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_building.php
executable file
·91 lines (73 loc) · 2.76 KB
/
edit_building.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
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/validation_functions.php"); ?>
<?php confirm_logged_in(); ?>
<?php include("includes/header.php"); ?>
<?php
$building = find_building_by_Building_Code($_GET["building"]);
if(!$building){
redirect_to("Modify_upc_update_data_buildings.php");
}
?>
<?php
if(isset($_POST["submit"])){
// validations
$required_fields = array("building_code", "building_name", "building_address");
validate_presences($required_fields);
/*$fields_with_max_lengths = array("username" => 30);
validate_max_lengths($fields_with_max_lengths);*/
if(empty($errors)){
$code = $building["Building_Code"];
$building_code = mysql_prep($_POST["building_code"]);
$building_name = mysql_prep($_POST["building_name"]);
$building_address = mysql_prep($_POST["building_address"]);
$query = "UPDATE elec_upc_building_names ";
$query.= "SET ";
$query.= "Building_Code = '{$building_code}', ";
$query.= "Building_Name = '{$building_name}', ";
$query.= "Building_Address = '{$building_address}' ";
$query.= "WHERE ";
$query.= "Building_Code = '{$code}' ";
$query.= "LIMIT 1";
echo "Query Fire thai Che?";
$result = mysqli_query($connection,$query);
echo "ha";
if($result){
$_SESSION["message"] = "Building Information Updated";
redirect_to("Modify_upc_update_data_buildings.php");
}
else{
//echo "Error is:" . mysqli_error($connection);
$_SESSION["message"] = "Building Information Update Failed";
}
}
}
?>
<div class = "row2">
<div class ="col1">
</div>
<div class="col2">
<?php echo message(); ?>
<?php echo form_errors($errors); ?>
<div>
<h2>Edit Building <?php echo htmlentities($building["Building_Code"]); ?></h2>
(Inset <b>NULL</b> in case of leaving the textfield blank)
</div>
<form action="edit_building.php?building=<?php echo urlencode($building["Building_Code"]); ?>" method="post">
<p>Building Code:
<input type="text" name="building_code" value="<?php echo htmlentities($building["Building_Code"]); ?>" />
</p>
<p>Building Name:
<input type="text" name="building_name" value="<?php echo htmlentities($building["Building_Name"]); ?>" />
</p>
<p>Building Address:
<input type="text" name="building_address" value="<?php echo htmlentities($building["Building_Address"]); ?>" />
</p>
<input type="submit" name="submit" value="Edit building" />
</form>
<br/>
<a href="Modify_upc_update_data_buildings.php">Cancel</a>
</div>
</div>
<?php include("includes/footer.php"); ?>