-
Notifications
You must be signed in to change notification settings - Fork 0
/
addhospital.php
135 lines (106 loc) · 4.2 KB
/
addhospital.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
<?php
$conn = mysqli_connect('localhost', 'rahul', 'whiplash10', 'covid_data');
// checking if it has connected properly
if(!$conn){
echo 'database connection error!: ' . mysqli_connect_error();}
$street = $borough = $hospital_name = $zipcode = '';
$hospital_phone = 'please do not put area code';
$errors = array('hospital_name'=>'', 'street'=>'', 'hospital_phone'=>'', 'borough'=>'', 'zipcode'=>'');
if(empty($_GET['hospital_name'])){
echo 'A hospital name is required <br />';}
else{
$hospital_name = $_GET['hospital_name'];
if(!preg_match('/^[a-zA-X\s]+$/', $hospital_name)){
$errors['hospital_name'] = "The hospital's name must be letters and spaces only <br />";}
}
if(empty($_GET['street'])){
echo 'A street for the hospital is required <br />';}
else{
$street = $_GET['street'];
if(!preg_match('/^[a-zA-X\s]+$/', $street)){
$errors['street'] = 'The street for the hospital must be letters and spaces only <br />';}
}
if(empty($_GET['borough'])){
echo 'A borough for the hospital is required <br />';}
else{
$borough = $_GET['borough'];
if(!preg_match('/^[a-zA-X\s]+$/', $borough)){
$errors['borough'] = 'The borough for the hospital must be letters and spaces only <br />';}
}
if(empty($_GET['hospital_phone'])){
echo 'A phone number for the hospital is required <br />';}
else{
$hospital_phone = $_GET['hospital_phone'];
if(!preg_match('/^[1-9][0-9]{9}+$/', $hospital_phone)){
$errors['hospital_phone'] = 'The hospital phone number must be exactly 10 digits <br />';}
}
if(empty($_GET['zipcode'])){
echo 'A hospital zipcode is required <br />';}
else{
$zipcode = $_GET['zipcode'];
if(!preg_match('/^[1-9][0-9]{5}+$/', $zipcode)){
$errors['zipcode'] = 'The zipcode must be exactly 6 digits <br />';}
}
if(array_filter($errors)){
echo 'THERE ARE ERRORS IN THE FORM';
}
else{
$hospital_name = mysqli_real_escape_string($conn, $_GET['hospital_name']);
$street = mysqli_real_escape_string($conn, $_GET['street']);
$borough = mysqli_real_escape_string($conn, $_GET['borough']);
$hospital_phone = mysqli_real_escape_string($conn, $_GET['hospital_phone']);
$zipcode = mysqli_real_escape_string($conn, $_GET['zipcode']);
$sql = "INSERT INTO hospitals(name, streetname, borough, phonenumber, zipcode) VALUES ('$hospital_name', '$street', '$borough', '$hospital_phone', '$zipcode')";
if(mysqli_query($conn, $sql)){
header('Location: adddata.php');
} else{
echo 'query error: ' . mysqli_error($conn);
}
}
?>
<!DOCTYPE html>
<html land="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" href="contributerregistration.css" href="dashboard/css/bootstrap.css">
<?php include('header.php'); ?>
<section class="container grey-text">
<h3 class="center">Add a Hospital
</h4>
<h5 class="center">State: Maharastra
</h5>
<h5 class="center">City: Pune
</h5>
<form class="blue lighten-4" action="addhospital.php" method"GET">
<label>Hospital Name:</label>
<input type="text" name="hospital_name" value="<?php echo htmlspecialchars($hospital_name) ?>">
<div class="red-text">
<?php echo $errors['hospital_name']; ?>
</div>
<label>Street Name:</label>
<input type="text" name="street" value="<?php echo htmlspecialchars($street) ?>">
<div class="red-text">
<?php echo $errors['street']; ?>
</div>
<label>Borough:</label>
<input type="text" name="borough" value="<?php echo htmlspecialchars($borough) ?>">
<div class="red-text">
<?php echo $errors['borough']; ?>
</div>
<label>Hospital Phone Number:</label>
<input type="text" name="hospital_phone" value="<?php echo htmlspecialchars($hospital_phone) ?>">
<div class="red-text">
<?php echo $errors['hospital_phone']; ?>
</div>
<label>Zipcode:</label>
<input type="text" name="zipcode" value="<?php echo htmlspecialchars($zipcode) ?>">
<div class="red-text">
<?php echo $errors['zipcode']; ?>
</div>
<div class="center">
<input type="submit" name="submit" value="submit" class"btn blue">
</div>
</form>
</section>
<?php include('footer.php'); ?>
</html>