-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreatequiz2.php
More file actions
53 lines (42 loc) · 1.27 KB
/
Copy pathcreatequiz2.php
File metadata and controls
53 lines (42 loc) · 1.27 KB
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
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
//Check for empty fields
if(empty($_POST['question'])||
empty($_POST['correct_answer']) ||
empty($_POST['wrong_answer1']) ||
empty($_POST['wrong_answer2']) ||
empty($_POST['wrong_answer3']))
{
echo '<script>';
echo 'alert("Please, fill all fields");';
echo 'window.location = "add_quiz2.php"';
echo '</script>";';
exit();
}
//Create short variables
$question = $_POST['question'];
$correct_answer = ($_POST['correct_answer']);
$wrong_answer1 = ($_POST['wrong_answer1']);
$wrong_answer2 = ($_POST['wrong_answer2']);
$wrong_answer3 = ($_POST['wrong_answer3']);
//connect to the database
require_once('db_conn.php');
//Create the insert query
$query = "INSERT INTO quiz2
-- (questionid, name, choice1, choice2, choice3, answer)
VALUES (NULL, '".$question."','".$wrong_answer1."','".$wrong_answer2."','".$wrong_answer3."','".$correct_answer."')";
$result = $dbc->query($query);
if($result){
echo '<script>';
echo 'alert("Your question was saved");';
echo 'window.location = "manage2.php"';
echo '</script>";';
} else {
echo '<script>';
echo 'alert("Something went wrong, try again");';
echo 'window.location = "add_quiz2.php"';
echo '</script>";';
}
$dbc->close();
?>