-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtakeSurvey.php
More file actions
76 lines (62 loc) · 2.36 KB
/
Copy pathtakeSurvey.php
File metadata and controls
76 lines (62 loc) · 2.36 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Taking Survey</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: sans-serif; text-align: center;}
</style>
</head>
<body>
<?php
// Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect them to welcome page
if(!isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] !== true){
header("location: welcome.php");
exit;
}
// Include config file
require_once "config.php";
// Create connection
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$current_username = $_SESSION["username"];
//echo $current_username;
$getUserInfo = "SELECT currency from User WHERE username = '$current_username'";
$purse = $conn->query($getUserInfo);
$purse = $purse->fetch_assoc();
$purse = $purse["currency"];
$surveyID = $_GET['selection'];
$loadSurvey = "SELECT company_name, questions, value FROM Surveys WHERE Survey_ID = $surveyID";
$result = $conn->query($loadSurvey);
$survey = $result->fetch_assoc();
$company = $survey["company_name"];
$surVal = $survey["value"];
?>
<p><h1 align="center"> Poller </h1></p>
<p align="right"><strong><font size="+1"><?= $current_username?> $<?= $purse ?> </font></strong></p>
<p align="center"><strong><?= $company ?> Survey:</strong> For each statement, enter the degree to which you agree from 0 to 5</p>
<?php
$Qarray = array($surVal/10);
parse_str($survey["questions"],$Qarray);
echo "<form action='congrats.php' method=get>"; // Upon submission, redirects to intermediary page
$i=1;
foreach ($Qarray as $question){
echo "Q$i: $question <input name='choice$i' type=text size=1 ><br><br>";
$i++;
}
echo "<input type=submit class='btn btn-primary' value='Submit Answers'>
<input type='hidden' name='ptsEarned' value=$surVal>
<input type='hidden' name='surveyTaken' value=$surveyID>";
//echo "<input type='hidden' name='ptsEarned' value=$surVal>";
//echo "<input type='hidden' name='form_submitted' value=$surVal/10>";
echo "</form>";
$conn->close();
?>
</body>
</html>