-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquizInv.php
113 lines (104 loc) · 3.94 KB
/
quizInv.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
<?php
include 'config.php';
error_reporting(0);
if (isset($_POST['submit'])) {
$form = $_GET['form'];
$owner = $_GET['owner'];
$answers = $_POST['answers'];
$sql = "SELECT * FROM users WHERE email='$email'";
$result = mysqli_query($conn, $sql);
if (!$result->num_rows > 0) {
$sql = "INSERT INTO submits (owner, formname, answers)
VALUES ('$owner', '$form', '$answers')"; //add a row to the table
$result = mysqli_query($conn, $sql);
if ($result) {
echo "<script>alert('Wow! Form Registration Completed.')</script>";
$_SESSION['formname'] = $qName;
header("Location: sent.php");
$form = '';
$owner = '';
$answers = '';
} else {
echo "<script>alert('Woops! Something Wrong Went.')</script>";
}
}
}
?>
<?php
if (isset($_GET['form'])&&isset($_GET['owner'])) {
$form = $_GET['form'];
$owner = $_GET['owner'];
}else{
header("Location: home.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet">
<title>Quiz invite</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Ask Bin</h1>
<section class="menu">
<ul class="menu-list">
<li><a href="home.php">Home</a></li>
<li onclick="theme()">Change theme</li>
<li><a href="about.php">About us</a></li>
<li class="active"><a href="login.php">My quizzes</a></li>
</ul>
<button>
<i class="fas fa-times"></i>
<i class="fas fa-bars"></i>
</button>
</section>
</header>
<section class="formCon">
<section class="form">
<form action="" method="POST">
<p class="title">
<?php
echo $form;
?>
</p>
<?php
$servername = "mysql:host=localhost;dbname=ask-bin";
$username = "root";
$password = "";
$conn = new PDO($servername,$username,$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM forms WHERE owner='$owner' AND formname='$form'";
$result = $conn->query($sql);
if($result->rowCount() > 0){
while($row = $result->fetch()){
$array = str_split($row['questions']);
$x=1;
echo '<p class="questioned">';
foreach ($array as $char) {
echo $char;
if($char=='?'){
echo '</p><input type="text" name="answer'.$x.'" placeholder="Answer" class="txt">';
if($x<$row['numberofquestions'])
echo '<p class="questioned">';
$x++;
}
}
}
// Free result set
unset($result);
}
?>
<input type="hidden" name="answers" id="astxt">
<button type="button" class="btn" onclick="ansr()">Submit</button>
<button name="submit" id="ansrbtn" hidden>Submit</button>
</form>
</section>
</section>
<script src="app.js"></script>
</body>
</html>