-
Notifications
You must be signed in to change notification settings - Fork 0
/
editOwner.php
110 lines (88 loc) · 3.69 KB
/
editOwner.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
<?php
require("session.php");
require "connect.php";
$name = $email = $phone = $address = $owner_id = "";
$errors = ["name" => "", "email" => ""];
if (isset($_POST['update_owner']) && isset($_POST['owner_id']) && !empty($_POST["owner_id"])) {
$owner_id = mysqli_real_escape_string($conn, $_POST["owner_id"]);
if (empty($_POST["email"])) {
$errors["email"] = "An email is required. <br/>";
} else {
$email = htmlspecialchars($_POST["email"]);
}
if (empty($_POST["name"])) {
$errors["name"] = "An name is required. <br/>";
} else {
$name = htmlspecialchars($_POST["name"]);
}
$address = htmlspecialchars($_POST["address"]);
$phone = htmlspecialchars($_POST["phone"]);
if (!array_filter($errors)) {
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$phone = mysqli_real_escape_string($conn, $_POST["phone"]);
$address = mysqli_real_escape_string($conn, $_POST["address"]);
$sql = "UPDATE owner
SET name='$name',email='$email',phone='$phone',address='$address'
WHERE owner_id='$owner_id';";
if (mysqli_query($conn, $sql)) {
header("Location: ownerDetails.php?id=" . $owner_id);
} else {
echo "query error: " . mysqli_error($conn);
}
}
} else {
$owner_id = mysqli_real_escape_string($conn, $_POST["owner_id"]);
$sql = "SELECT * FROM owner WHERE owner_id='$owner_id'";
$result = mysqli_query($conn, $sql);
$owner = mysqli_fetch_assoc($result);
$name = $owner['name'];
$email = $owner['email'];
$phone = $owner['phone'];
$address = $owner['address'];
}
?>
<?php include "header.php"; ?>
<div class="flex justify-center items-center">
<div class="w-full m-8 ">
<form action="editOwner.php" method="post" class="max-w-md mx-auto w-full flex flex-col justify-center items-center gap-4 bg-gray-50 rounded-xl p-4 shadow overflow-hidden">
<div class="p-3 text-center">
<h1 class="text-3xl text-gray-900 my-2">
<b>Edit Owner Details</b>
</h1>
</div>
<div class="w-full ">
<label for="name" class="label required">
Name
</label>
<input name="name" type="text" class=" input " placeholder="Full name" autocomplete="name" maxlength="50" value="<?php echo $name; ?>" required>
<p class="error_text"><?php echo $errors["name"] ? $errors["name"] : ""; ?> </p>
</div>
<input name="owner_id" type="hidden" value="<?php echo $owner_id; ?>">
<div class="w-full ">
<label for="email" class="label required">
Email
</label>
<input name="email" type="email" class=" input " maxlength="50" placeholder="Email address" autocomplete="email" value="<?php echo $email; ?>" required>
<p class="error_text"><?php echo $errors["email"] ? $errors["email"] : ""; ?> </p>
</div>
<div class="w-full ">
<label for="phone" class="label required">
Phone
</label>
<input name="phone" type="tel" class=" input " maxlength="50" placeholder="Phone number" autocomplete="phone" value="<?php echo $phone; ?>" required>
</div>
<div class="w-full ">
<label for="address" class="label">
Address
</label>
<textarea name="address" class="input" placeholder="Address" maxlength="100" autocomplete="address"><?php echo $address; ?></textarea>
</div>
<div class="w-full flex gap-4 ">
<a href="/rms/ownerDetails.php?id=<?php echo $owner_id; ?>" class="btn secondary w-auto"> Cancel </a>
<input name="update_owner" type="submit" class=" btn primary" value="Update Owner">
</div>
</form>
</div>
</div>
<?php include "footer.php"; ?>