-
Notifications
You must be signed in to change notification settings - Fork 1
/
faq.php
90 lines (78 loc) · 2.16 KB
/
faq.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
<?php
require_once __DIR__ . "/database.php";
require_once __DIR__ . "/configVars.php";
$db = new Database(...$DB_CONFIG);
$message = "";
function createTable()
{
global $createCheck;
$createCheck = true;
$create_faq = "CREATE TABLE IF NOT EXISTS faq(
question varchar(200) PRIMARY KEY,
answer varchar(200)
)";
$res = $db->fullExecute($create_faq);
}
$data;
$rs = $db->fullFetch("SELECT * FROM faq WHERE answer IS NOT NULL");
if (!$rs) {
$data = array();
} else {
$data = $rs;
}
if (isset($_POST["submitQuestion"])) {
$data;
$question = trim($_POST["question"]);
if (strlen($question) == 0) {
$message = "Unable to add Empty Question";
} else {
$rs = $db->fullFetch("SELECT * FROM faq WHERE question='$question'");
if (count($rs) > 0) {
$message = "Same Question Already Posted";
} else {
$rs = $db->fullExecute("INSERT INTO faq(question) VALUES('$question')");
if ($rs) {
$message = "Question Successfully Posted";
} else {
$message = "Unable to POST Question";
}
}
}
}
?>
<html>
<head>
<title>
FAQ
</title>
<link rel="stylesheet" type="text/css" href="./public/css/faqcss.css" />
</head>
<body>
<div class="faq">
<img src="./public/images/faqbg.jpg" alt="FAQ" width="300" height="500" />
</div>
<div class="faqs">
<?php
if (count($data) == 0) {
echo "<span class='question'>NO QUESTIONS ANSWERED YET</span>";
} else {
foreach ($data as $qa) {
echo "<span class='question'>" . htmlentities($qa["question"]) . "</span>";
echo "<br />";
echo "<span class='answer'>" . htmlentities($qa["answer"]) . "</span>";
echo "<br />";
echo "<br />";
echo "<hr />";
}
}?>
</div>
<br />
<br />
<br />
<form method="POST">
<textarea name="question" id="commentarea" placeholder="Add your question here.."></textarea>
<input type="submit" name="submitQuestion" value="Submit">
</form>
<span class="message"><?=htmlentities($message)?></span>
</body>
</html>