-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_question.php
313 lines (255 loc) · 7.28 KB
/
insert_question.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
// print_r($_SESSION);
session_start();
$error = "";
if(!isset($_SESSION["admin_db"]) || $_SESSION["admin_db"]== ""){
header("location:login.php");
// echo "admin_db Not set ";
// echo "<br>admin_db is: ".$_SESSION["admin_db"];
}
if (isset($_REQUEST["back"])) {
header("location:admin.php");
// echo "going to admin";
}
if (isset($_REQUEST["login"])) {
$question = trim($_REQUEST["question"]);
$answer = trim($_REQUEST["answer"]);
$opt_a = trim($_REQUEST["opt_a"]);
$opt_b = trim($_REQUEST["opt_b"]);
$opt_c = trim($_REQUEST["opt_c"]);
$opt_d = trim($_REQUEST["opt_d"]);
if(empty($question)|| empty( $answer)|| empty($opt_a)|| empty($opt_b)||empty($opt_c)||empty($opt_d)){
$error = "<div style='text-align:center;font-size:25px; color:black;background-color:red; '>Field Cannot Be Blank</div>";
}
else{
// echo"ready to insert";
include "conn_detail.php";
$sql = "SELECT * From question_answer";
$result = $conn->query($sql);
if($result == ""){
$sql = "CREATE TABLE question_answer ( id INT AUTO_INCREMENT PRIMARY KEY , question VARCHAR(300),answer VARCHAR(10),opt_a VARCHAR(300),opt_b VARCHAR(300),opt_c VARCHAR(300),opt_d VARCHAR(300) ) ";
$conn->query($sql);
}
// $count = 20;
// $sql = " INSERT INTO question_answer (question,answer,opt_a,opt_b,opt_c,opt_d) VALUES('who am i ','a','i don t know ','antying ','a machine ','a resposnbible person ')";
// while($count--){
// $conn->query($sql);
// }
// INSERT INTO question_answer (question,answer,opt_a,opt_b,opt_c,opt_d) VALUES('who am i ','a','i don t know ','antying ','a machine ','a resposnbible person ')
// echo $result;
// echo"eresult is: ";
$sql = "INSERT INTO question_answer (question,answer,opt_a,opt_b,opt_c,opt_d) VALUES('$question','$answer','$opt_a','$opt_b','$opt_c','$opt_d')";
// echo "query is: ",$sql;
if($conn->connect_error ==""){
// echo "connected sucessfully";
if($conn->query($sql) === TRUE){
echo " <div style='text-align:center;font-size:25px; color:black;background-color:green; '>inserted succesfully</div>";
}
else{
// echo $conn->error;
// echo "NOt able --to insert";
}
}
else{
// echo "not able to insert";
}
}
}
else{
// echo "not ready to insert";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert Question</title>
<link rel="icon" href="favicon.png" type="image/x-icon">
</head>
<style>
body{
background-color: rgb(34,34,34);
}
#form_boundary{
width: 300px;
margin :auto;
border-style :solid;
padding:10px;
position: relative;
top:30px;
border-radius:3px;
text-align:center;
background-color:rgb(43, 75, 75);
color:whitesmoke;
}
input{
background-color:rgb(59, 54, 54) ;
margin-bottom:15px;
position: relative;
/* right: -10%; */
/* left:10px; */
width: 80%;
color:rgb(255, 255, 255);
}
button{
background-color: rgb(24, 145, 145);
color:black;
font-size: 15px;
width: 83%;
margin:4px;
color:whitesmoke;
}
button:hover{
background-color: rgb(24, 168, 168);
color:black;
}
body {
background-color: rgb(34, 34, 34);
min-height: 100vh;
/* background-color: rgb(34, 34, 34); */
background-image: url(quiz_image.jpg);
/* background-repeat: no-repeat; */
background-size: cover;
margin:0px;
}
#form_boundary {
width: 380px;
position: relative;
top: 30px;
margin: auto;
border-style: solid;
border-width: 1px;
padding: 10px;
border-radius: 3px;
/* background-color: darkslategray; */
background-color: rgba(0,0,0,0.7);
padding-bottom:27px;
margin-bottom: 86px;
<?php if($display_form === "false"){
echo' display:none;';
}
?>
}
input {
background-color: transparent;
/* margin: 5px; */
/* padding:5px; */
position: relative;
/* right: -10%; */
right: 0px;
color: rgb(255, 255, 255);
width:90% ;
}
button {
/* background-color: #008CBA; */
/* background-color: #0067ba85;; */
padding:5px;
color: black;
font-size: large;
color:whitesmoke;
/* background-color: rgb(24, 145, 145); */
background-color: black;
color: white;
font-size: 15px;
width: 92%;
}
input::placeholder{
color:rgba(250,250,250,0.7);
}
button:hover {
/* background-color: rgb(24, 168, 168); */
/* color: indigo; */
/* box-shadow: 0px 0px 5px 1px white; */
cursor:pointer;
box-shadow: 0px 0px 5px 1px white;
}
button:focus,input:focus {
/* background-color: rgb(24, 168, 168); */
box-shadow: 0px 0px 5px 1px white;
}
#test {
width: 259px;
position: fixed;
left: 10%;
right: 10%;
top: 10%;
color: white;
/* top: -144px; */
z-index: 4;
background-color: rgba(0,0,0,0.7) ;
border-style: solid;
border-color: white;
border-width: 1px;
text-align: center;
margin: auto;
height: 200px;
font-size: 30px;
}
.form_box {
position:relative;
/* border:1px solid white; */
}
.input_field{
position:relative;
margin:25px 5px;
}
.s1{
/* background-color:blue; */
/* text-align:right;; */
display:inline-block;
width:230px;
position:absolute;
text-align:right;
right:0px;
/* border:1px solid yellow; */
}
@media screen and (max-width:700px) {
.detail{
display:none;
}
.s1{
display:inline-block;
position :relative;
width:90%;
}
h3{
text-align:center;
}
#form_boundary{
width:90%;
}
#submit_button{
width:82%;
margin-left:8%;
}
button{
width:92%;
}
body{
height:120vh;
}
#heading {
text-align:center;
}
}
</style>
<body>
<div id = "form_boundary">
<form >
<p style="font-weight: 800;font-size:larger;"> Add New Question</p>
<hr >
<?php if ($error != "") echo "<p style='color:black'>$error<p>"; ?>
<br><input type="text" name="question" placeholder="Enter question">
<br><input type ="text"" name="answer" placeholder="Enter correct option">
<br><input type ="text"" name="opt_a" placeholder="Enter Answer A">
<br><input type ="text"" name="opt_b" placeholder="Enter Answer B">
<br><input type ="text"" name="opt_c" placeholder="Enter Answer C">
<br><input type ="text"" name="opt_d" placeholder="Enter Answer D">
<br><button type="submit" name="login">Add</button>
<button type = "submit" name="back"> Back</button>
<!-- <p>Don't have a account?<a href="registration_form.php">Sign up</a></p> -->
</form>
</div>
</body>
</html>