This repository has been archived by the owner on May 17, 2023. It is now read-only.
forked from if-itb/IF3110-2015-T1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
85 lines (81 loc) · 2.44 KB
/
index.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
<!DOCTYPE HTML>
<html>
<head>
<title>Home</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="/style/master.css" >
</head>
<body>
<?php
require 'query.php';
?>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$question['name']=test_input($_POST['name']);
$question['email']=test_input($_POST['email']);
$question['topic']=test_input($_POST['topic']);
$question['content']=test_input($_POST['content']);
$question['q_id']=$_POST['q_id'];
updateQuestion($question);
}
$tabQuestion = getAllQuestions();
$nQuestion = mysqli_num_rows($tabQuestion);
?>
<div class="view">
<h1>Simple Stack Exchange</h1><br>
<form id="search">
<input type="text" name="search">
<input type="submit" value="Search">
</form>
<div class="ask-here">
<div>Cannot find what are you looking for?</div>
<div><a href="ask.php" >Ask here</a></div>
</div>
<p id='head'>Recently Asked Question</p>
<hr>
<?php
if($nQuestion==0) {
echo "<div>No Question</div>";
} else{
while($question= mysqli_fetch_assoc($tabQuestion)){
?>
<div class="title"><a href="question.php?q_id=<?php echo $question['q_id']?>"><?php echo $question['topic']; ?></a></div>
<div class="row">
<div class="vote-col">
<div><?php echo $question['vote']; ?></div><br>
<div>Votes</div>
</div>
<div class="answer-col">
<div><?php echo countAnswer($question['q_id']); ?></div><br>
<div>Answer</div>
</div>
<div class="content-col">
<p> <?php echo substr($question['content'],0, 270); ?> </p>
</div>
<br>
<div class="other">
<div>asked by</div>
<div class="name"><?php echo $question['name']; ?></div><div> |</div>
<div class="edit"><a href="ask.php?q_id=<?php echo $question['q_id'].'&address=home';?>">edit</a></div><div> |</div>
<div class="delete"><a href="delete.php?q_id=<?php echo $question['q_id'];?>" onclick="return confirmDeletion()">delete</a></div>
</div>
<br>
</div>
<hr>
<?php
}
}
?>
</div>
<script src="/script/master.js"></script>
<?php
mysqli_close($conn);
?>
</body>
</html>