-
Notifications
You must be signed in to change notification settings - Fork 0
/
addOwner.php
98 lines (77 loc) · 3.09 KB
/
addOwner.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
<?php
require("session.php");
require "connect.php";
$name = $email = $phone = $address = "";
$errors = ["name" => "", "email" => ""];
if (isset($_POST['submit'])) {
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)) {
//there is no error in the form
$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 = "INSERT INTO owner(name,email,phone,address) VALUES('$name','$email','$phone','$address' ) ";
if (mysqli_query($conn, $sql)) {
header("Location: owners.php");
} else {
echo "quesry error: " . mysqli_error($conn);
}
}
}
?>
<?php include "header.php"; ?>
<div class="flex justify-center items-center">
<div class="w-full m-8 ">
<form action="addOwner.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-700 my-2">
<b>Add Owner</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>
<div class="w-full ">
<label for="email" class="label required">
Email
</label>
<input name="email" type="email" class=" input " placeholder="Email address" autocomplete="email" maxlength="50" 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 " placeholder="Phone number" autocomplete="phone" maxlength="50" value="<?php echo $phone; ?>" required>
</div>
<div class="w-full ">
<label for="address" class="label">
Address
</label>
<textarea name="address" class=" input " maxlength="100" placeholder="Address" autocomplete="address"><?php echo $address; ?></textarea>
</div>
<div class="w-full flex gap-4 ">
<a href="/rms/owners.php" class="btn secondary w-auto">
Cancel </a>
<input name="submit" type="submit" class=" btn primary " value="Add Owner">
</div>
</form>
</div>
</div>
<?php include "footer.php"; ?>