-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_new.php
151 lines (130 loc) · 4.72 KB
/
add_new.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
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<title>ADD NEW FORM</title>
<link rel="apple-touch-icon" sizes="76x76" href="logo.png">
<link rel="icon" href="logo.png">
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<style>
/* Styles for the loading div */
#loading {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
z-index: 9999;
color: #fff;
text-align: center;
padding-top: 20%;
}
.form-container {
background-color: #f2f2f2;
padding: 20px;
margin-bottom: 20px;
margin-right:0;
}
/* Styles to hide the content initially */
#content {
display: none;
}
</style>
</head>
<body>
<!-- Loading div -->
<div id="loading">
<div class="container">
<div class="preloader">
<span></span>
<span></span>
<span></span>
</div>
<div class="shadow"></div>
</div>
</div>
<!-- Your page content -->
<div id="content" >
<div class="header">
<img src="logo2.png" alt="Logo" class="logo">
<div class="menu">
<button class="add-disease-button" onclick="window.location.href='index.php'">back</button>
</div>
</div>
<div class="content">
<div class="form-container">
<h2>Add New Disease</h2>
<form method="POST" enctype="multipart/form-data">
<label for="name">Name:</label>
<input class="form-input" type="text" id="name" name="name" required>
<label for="image">Image:</label>
<input class="form-input" type="file" id="image" name="image" accept="image/*" required>
<label for="description">Description:</label>
<textarea class="form-input" id="description" name="description" rows="4" required></textarea>
<label for="prevention">Prevention:</label>
<textarea class="form-input" id="prevention" name="prevention" rows="4" required></textarea>
<label for="medicines">Medicines:</label>
<textarea class="form-input" id="medicines" name="medicines" rows="4" required></textarea>
<input class="form-button" type="submit" value="Add Disease">
</form>
<script>
// JavaScript to show the loading div and hide it after 3 seconds
document.onreadystatechange = function () {
var loadingDiv = document.getElementById('loading');
var contentDiv = document.getElementById('content');
if (document.readyState === 'loading') {
loadingDiv.style.display = 'block';
} else if (document.readyState === 'interactive') {
setTimeout(function() {
loadingDiv.style.display = 'none';
contentDiv.style.display = 'block';
}, 2000);
}
};
</script>
<?php
// Database connection parameters
$servername = "localhost";
$username = "root"; // Change this to your database username
$password = "root"; // Change this to your database password
$database = "doctor";
// Establishing the database connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Handling form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data and escape special characters
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$description = mysqli_real_escape_string($conn, $_POST["description"]);
$prevention = mysqli_real_escape_string($conn, $_POST["prevention"]);
$medicines = mysqli_real_escape_string($conn, $_POST["medicines"]);
// Upload image file
if(isset($_FILES['image'])) {
$image = $_FILES["image"]["name"];
$temp_image = $_FILES["image"]["tmp_name"];
$image_folder = "images/"; // Create a folder named "images" to store uploaded images
if(move_uploaded_file($temp_image, $image_folder.$image)) {
// Insert data into the database
$sql = "INSERT INTO diseases (name, description, prevention, medicines, image) VALUES ('$name', '$description', '$prevention', '$medicines', '$image')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
} else {
echo "Sorry, there was an error uploading your file.";
}
} else {
echo "No file selected.";
}
}
// Closing database connection
mysqli_close($conn);
?>
</body>
</html>