-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_poll.php
180 lines (136 loc) · 6.57 KB
/
user_poll.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
<?php
session_start();
$server="localhost";
$username="root";
$password="";
$database="delta_task3";
$con=mysqli_connect($server,$username,$password,$database);
$Sno=$_SESSION['Sno'];
$find="SELECT * FROM `delta_task3`.`trial` where `Sno`='$Sno'";
$found = mysqli_query($con, $find);
$polling = mysqli_fetch_array($found);
$option1_count=$polling['option1 count'];
$option2_count=$polling['option2 count'];
$option3_count=$polling['option3 count'];
$option4_count=$polling['option4 count'];
$driver=0;
$userid=$_SESSION['userid'];
$details="SELECT * FROM `delta_task3`.`details` where `Username`='$userid'";
$check = mysqli_query($con, $details);
$myDetail = mysqli_fetch_array($check);
if(isset($_POST['submit'])){
$choice=$_POST['poll'];
$user_voted_check = "SELECT * FROM `delta_task3`.`$polling[Question]` where `Username`='$userid'";
$query = mysqli_query($con, $user_voted_check);
if($query->num_rows>=1){
echo '<script>
alert("You have already voted");
</script>';
}
else{
if($choice==$polling['option1']){
$option1_count++;
$update = "UPDATE `delta_task3`.`trial` SET `option1 count`='$option1_count' where `Question`='$polling[Question]'";
$update2 = "INSERT INTO `delta_task3`.`$polling[Question]` (`Name`, `Username`, `Email`) VALUES ('$myDetail[Name]','$myDetail[Username]','$myDetail[Email]')";
if($con->query($update)==true&&$con->query($update2)==true){
echo '<script>
alert("Your choice is submitted");
</script>';
}
}
if($choice==$polling['option2']){
$option2_count++;
$update = "UPDATE `delta_task3`.`trial` SET `option2 count`='$option2_count' where `Question`='$polling[Question]'";
$update2 = "INSERT INTO `delta_task3`.`$polling[Question]` (`Name`, `Username`, `Email`) VALUES ('$myDetail[Name]','$myDetail[Username]','$myDetail[Email]')";
if($con->query($update)==true&&$con->query($update2)==true){
echo '<script>
alert("Your choice is submitted");
</script>';
}
}
if($choice==$polling['option3']){
$option3_count++;
$update = "UPDATE `delta_task3`.`trial` SET `option2 count`='$option2_count' where `Question`='$polling[Question]'";
$update2 = "INSERT INTO `delta_task3`.`$polling[Question]` (`Name`, `Username`, `Email`) VALUES ('$myDetail[Name]','$myDetail[Username]','$myDetail[Email]')";
if($con->query($update)==true&&$con->query($update2)==true){
echo '<script>
alert("Your choice is submitted");
</script>';
}
}
if($choice==$polling['option4']){
$option4_count++;
$update = "UPDATE`delta_task3`.`trial` SET `option4 count`='$option4_count' where `question`='$polling[Question]'";
$update2 = "INSERT INTO `delta_task3`.`$polling[Question]` (`Name`, `Username`, `Email`) VALUES ('$myDetail[Name]','$myDetail[Username]','$myDetail[Email]')";
if($con->query($update)==true&&$con->query($update2)==true){
echo '<script>
alert("Your choice is submitted");
</script>';
}
}
}
}
$con->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="user.css">
<link href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&display=swap" rel="stylesheet">
<title> Poll</title>
</head>
<body text="white">
<div class="nav">
<button id="logout" onclick="location.href='dashboard_user.php'">BACK</button>
<button id="logout" onclick="location.href='logout.php'">LOGOUT</button>
</div>
<div class="main">
<?php
echo "<div class=details>
<h5>NAME: $myDetail[Name]</h5><br>
<h5>USERNAME: $myDetail[Username]</h5><br>
<h5>EMAIL: $myDetail[Email]</h5><br></div> ";
?>
<div class="blank">
<h1>Cast your vote</h1>
<form action ="user_poll.php" method="POST">
<p id="heading"><?php echo $polling['Question']?>?</p>
<div class="align">
<input type="radio" class="options option1" id="option1" name="poll" value="<?php echo $polling['option1']?>">
<label for="option1" class="options option1"><?php echo $polling['option1']?></label><br>
<input type="radio" class="options option2" id="option2" name="poll" value="<?php echo $polling['option2']?>">
<label for="option2" class="options option2"><?php echo $polling['option2']?></label><br>
<input type="radio" class="options option3" name="poll" id="option3" value="<?php echo $polling['option3']?>">
<label for="option3" class="options option3"><?php echo $polling['option3']?></label><br>
<input type="radio" class="options option4" id="option4" name="poll" value="<?php echo $polling['option4']?>">
<label for="option4" class="options option4"><?php echo $polling['option4']?></label><br>
<input name="submit" type="submit" id="btn" value="Submit">
</div></form>
</div>
<div class="img">
<img id="img" src="deltaLogoGreen.png">
</div>
</div>
<!-- <div class="container" > -->
<!-- <h1>Cast your vote</h1>
<form action ="user_poll.php" method="POST">
<p id="heading"><?php echo $polling['Question']?>?</p>
<input type="radio" class="options option1" name="poll" value="<?php echo $polling['option1']?>">
<label for="option1" class="options option1"><?php echo $polling['option1']?></label><br>
<input type="radio" class="options option2" name="poll" value="<?php echo $polling['option2']?>">
<label for="option2" class="options option2"><?php echo $polling['option2']?></label><br>
<input type="radio" class="options option3" name="poll" value="<?php echo $polling['option3']?>">
<label for="option3" class="options option3"><?php echo $polling['option3']?></label><br>
<input type="radio" class="options option4" name="poll" value="<?php echo $polling['option4']?>">
<label for="option4" class="options option4"><?php echo $polling['option4']?></label><br>
<input name="submit" type="submit" id="btn" value="Submit">
</form> -->
<!-- </div> -->
<div class="bottom">
<p style="margin:top 10px;">Made with ❤ by Raghav</p>
</div>
</body>
</html>