-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredetails.php
174 lines (150 loc) · 6.87 KB
/
predetails.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// Include config file
require_once "config.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;
}
// Define variables and initialize with empty values
$cust_name = $drug_name = $condition_ =$dose= $quantity=$doctor_name ="";
$cust_name_err = $drug_name_err = $condition__err=$dose_err= $quantity_err = $doctor_name_err= "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate cust_name
if(empty(trim($_POST["cust_name"]))){
$cust_name_err = "Please enter a cust_name.";
} else{
// Prepare a select statement
$sql = "SELECT cust_name FROM prescription_detail WHERE cust_name = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_cust_name);
// Set parameters
$param_cust_name = trim($_POST["cust_name"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$cust_name_err = "This cust_name is already taken.";
} else{
$cust_name = trim($_POST["cust_name"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Validate drug_name
if(empty(trim($_POST["drug_name"]))){
$drug_name_err = "Please enter a drug_name.";
} else{
$drug_name = trim($_POST["drug_name"]);
}
if(empty(trim($_POST["condition_"]))){
$condition__err = "Please enter a condition_.";
} else{
$condition_ = trim($_POST["condition_"]);
}
if(empty(trim($_POST["dose"]))){
$dose_err = "Please enter a dose.";
} else{
$dose = trim($_POST["dose"]);
}
if(empty(trim($_POST["quantity"]))){
$quantity_err = "Please enter a quantity.";
} else{
$quantity = trim($_POST["quantity"]);
}
if(empty(trim($_POST["doctor_name"]))){
$doctor_name_err = "Please enter a doctor_name.";
} else{
$doctor_name = trim($_POST["doctor_name"]);
}
$_SESSION["cust_name"]=$cust_name;
$_SESSION["drug_name"] = $drug_name;
$_SESSION["quantity"] = $quantity;
$_SESSION["doctor_name"] = $doctor_name;
// Check input errors before inserting in database
if(empty($cust_name_err) && empty($drug_name_err) && empty($condition_err) && empty($condition__err) && empty($dose_err) && empty($doctor_name_err)){
// Prepare an insert statement
$stmt=mysqli_stmt_init($link);
if(mysqli_stmt_prepare($stmt, "INSERT INTO prescription_detail (cust_name, drug_name,condition_, dose,quantity, doctor_name) VALUES (?, ?,?,?,?,?)")){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ssssis", $param_cust_name, $drug_name,$condition_, $dose,$quantity, $doctor_name);
$param_cust_name=$cust_name;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
echo "succesfully entered";
} else{
echo "Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PRESCRIPTION DETAIL</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body{ font: 14px sans-serif; }
.wrapper{ width: 350px; padding: 20px; }
</style>
</head>
<body>
<div style="padding: 10px; width: 600px; margin: auto; margin-top: 40px; border:solid; border: radius 20px; background-color: #edf2f4">
<h2 style="text-align: center;">PRESCRIPTION DETAILS</h2>
<hr>
<p style="text-align: center;">Please fill this form with prescription detail.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($cust_name_err)) ? 'has-error' : ''; ?>">
<label>cust_name</label>
<input type="text" name="cust_name" class="form-control" value="<?php echo $cust_name; ?>">
<span class="help-block"><?php echo $cust_name_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($drug_name_err)) ? 'has-error' : ''; ?>">
<label>drug_name</label>
<input type="text" name="drug_name" class="form-control" value="<?php echo $drug_name; ?>">
<span class="help-block"><?php echo $drug_name_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($condition__err)) ? 'has-error' : ''; ?>">
<label>condition_</label>
<input type="text" name="condition_" class="form-control" value="<?php echo $condition_; ?>">
<span class="help-block"><?php echo $condition__err; ?></span>
</div>
<div class="form-group <?php echo (!empty($dose_err)) ? 'has-error' : ''; ?>">
<label>dose</label>
<input type="text" name="dose" class="form-control" value="<?php echo $dose; ?>">
<span class="help-block"><?php echo $dose_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($quantity_err)) ? 'has-error' : ''; ?>">
<label>quantity</label>
<input type="text" name="quantity" class="form-control" value="<?php echo $quantity; ?>">
<span class="help-block"><?php echo $quantity_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($doctor_name_err)) ? 'has-error' : ''; ?>">
<label>doctor_name</label>
<input type="text" name="doctor_name" class="form-control" value="<?php echo $doctor_name; ?>">
<span class="help-block"><?php echo $doctor_name_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
<p><a href="dlink.php">PROCEED</a>.</p>
</form>
</div>
</body>
</html>