-
Notifications
You must be signed in to change notification settings - Fork 0
/
birdsadd.php
139 lines (123 loc) · 3.84 KB
/
birdsadd.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
?>
<!doctype html>
<html>
<head>
<title>Birds </title>
<style>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background: #484848;
}
.topnav {
overflow: hidden;
background-color:rgba(44, 130, 201, 1);
height: 70px;
border: 3px solid #3333ff
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 35px;
font-weight: bold;
}
.topnav-right {
float: right;
}
fieldset {
background: #FAFAFA;
padding: 10px;
margin:auto;
max-width:450px;
box-shadow: 1px 1px 25px rgba(0, 0, 0, 0.35);
border-radius: 10px;
border: 6px solid rgba(44, 130, 201, 1);
}
</style>
</head>
<body>
<div class="topnav">
<a class="active" href="index.php"><img src="ic_add_pet.png"></a>
<a href="birds.php">Birds</a>
<div class="topnav-right">
<a href="logout.php">logout</a>
</div>
</div>
<form>
<button type="submit" formaction="birds.php" style="margin:15px;height: 30px;width: 100px;cursor:pointer;border-radius:15px;
border: 3px solid #3333ff;background-color:rgba(44, 130, 201, 1);color:#f2f2f2;font-size:17px;">Back</button>
</form>
<form method="post" action="birdsadd.php">
<fieldset>
<input type="text" name="id" placeholder=" Enter pet_id" style="width:100%;height:30px;
border: 2px solid rgba(44, 130, 201, 1); border-radius:3px; background:transparent;" required>
<br><br>
<input type="text" name="category" placeholder=" Enter pet_category" style="width:100%;height:30px;
border: 2px solid rgba(44, 130, 201, 1); border-radius:3px; background:transparent;" required>
<br><br>
<input type="text" name="type" placeholder=" Enter bird type" style="width:100%;height:30px;
border: 2px solid rgba(44, 130, 201, 1); border-radius:3px; background:transparent;" required>
<br><br>
<select name="noise" style="width:100%;height:30px;
border: 2px solid rgba(44, 130, 201, 1); border-radius:3px; background:transparent;">
<option value="low">low</option>
<option value="moderate">moderate</option>
<option value="high">high</option>
</select>
<br><br>
<input type="number" name="cost" placeholder=" Enter cost" style="width:100%;height:30px;
border: 2px solid rgba(44, 130, 201, 1); border-radius:3px; background:transparent;" min="0" required>
<br><br>
<input type="submit" name="submit" value="save" style="width:100%;height:30px;
border: 2px solid rgba(44, 130, 201, 1); border-radius:3px; cursor:pointer;background-color:rgba(44, 130, 201, 1)"> 
</fieldset>
</form>
</body>
</html>
<?php
if(isset($_POST["submit"]))
{
// define variables and set to empty values
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Petshop_management";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo " CONNECTION ESTABLISHED \r\n";
//echo " INSERTION IN PROCESS";
$id = $_POST["id"];
$category = $_POST["category"];
$type= $_POST["type"];
$noise = $_POST["noise"];
$cost = $_POST["cost"];
$sql = "INSERT INTO pets( pet_id,pet_category,cost)
VALUES ('$id','$category','$cost');
INSERT INTO birds(pet_id,type,noise)
VALUES('$id','$type','$noise')";
if ($conn->multi_query($sql) == TRUE) {
echo'<div>
<h1 style="color:#f2f2f2;font-size:20px; font-family: "Roboto", sans-serif;margin:auto;">New record of id='
.$id. ' inserted successfully</h1>
</div>';
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>