forked from Nebilsolomon/Survey_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion.php
More file actions
82 lines (69 loc) · 2.64 KB
/
Question.php
File metadata and controls
82 lines (69 loc) · 2.64 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
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
<?php
$v = session_start();
// Include database credentials
$conn = mysqli_connect('localhost','root', '', 'Survey');
if(!$conn) {
echo 'Connection error: ' . mysqli_connect_error();
} else {
// echo 'Successfully connected';
// header("Location: Question.php?id=$user_id&name=$user_name");
//header('Location: Question.php');
}
if (isset($_POST['Create'])) {
$questionName = mysqli_real_escape_string($conn, $_POST["QuestionName"]);
$description = mysqli_real_escape_string($conn, $_POST["Description"]);
$Qtype = mysqli_real_escape_string($conn, $_POST["QType"]);
$surveyID = $_SESSION["SCode"];
// Construct SQL query
$sql = "INSERT INTO Question(QName, QDescription, QType, Survey_Code,question_ts)
VALUES('$questionName','$description','$Qtype','$surveyID',current_timestamp);";
// Execute query
if(mysqli_query($conn, $sql)) {
//$questionID = mysqli_insert_id($conn);
$sql = "SELECT * FROM Question WHERE QName = '$questionName' and Survey_Code = $surveyID;";
$result = mysqli_query($conn, $sql);
$Question = mysqli_fetch_assoc($result);
$_SESSION["QID"] = $Question['Question_ID'];
$_SESSION["QType"] = $Question['QType'];
// $QuestionName = $Question_Id_type['QuestionName'];
// Redirect to a new page with the user ID and name as parameters
//header("Location: UserPage.php?id=$user_id&name=$user_name");
header("Location: AnswerOption.php");
exit();
} else {
echo 'Query error: ' . mysqli_error($conn);
}
}
if(isset($_POST['Finish'])){
header("Location: DeleteSurvey.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<div class="header">
<h1>Magic Survey</h1>
<p>For all of your survey needs</p>
</div>
</head>
<body>
<form class="form" action="Question.php" method="POST">
<h1>Create Question</h1>
<label>Question Name </label>
<input type="text" name="QuestionName">
<label>Description</label>
<input type="text" name="Description">
<label>Choose A Question Type</label>
<div style="display:flex; flex-direction: row;align-items: center">
<input type="radio" name="QType" value="T/F">
<label for="T/F">True/False</label><br>
<input type="radio" name="QType" value="MC">
<label for="MC">Multiple Choice</label><br>
</div>
<input type=submit name="Create" value = "Create">
<input type=submit name="Finish" value = "Finish">
</form>
</body>
</html>