-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnswers.php
More file actions
228 lines (96 loc) · 2.14 KB
/
Copy pathAnswers.php
File metadata and controls
228 lines (96 loc) · 2.14 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
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
<?php
include "header.php";
?>
<form>
<br>
<br>
<table border=1 width="100%">
<tr>
<td width="70%">
</td>
</tr>
<?php
$qid= $_REQUEST['qid'];
echo "<input type=text name=qid value=".$qid." hidden=true />";
$result = mysql_query("select * from question where q_id=".$_REQUEST['qid']);
// echo $result;
while($row = mysql_fetch_array($result))
{
echo "<tr>
<td>";
echo "<h1><a href=Answers.php?qid=".$row['q_id'].">".$row['question']."</a></h1>";
echo "<br><span >Asked by ".getname($row['u_id']);
echo " on ".$row['datetime']."</span>";
echo "</td></tr>";
}
?>
</table>
<br>
<table width="100%" border="1">
<tr>
<td width="70%"><b>Answers<b>
</td>
<td width="15%"><b>By<b>
</td>
<td width="15%"><b>On<b>
</td>
</tr>
<?php
$result = mysql_query("select * from answer where q_id=".$_REQUEST['qid']);
// echo $result;
while($row = mysql_fetch_array($result))
{
echo "<tr>
<td>";
echo $row['answer'];
echo "</td>";
echo "
<td>";
echo getname($row['u_id']);
echo "</td>";
echo "
<td>";
echo $row['datetime'];
echo "</td>
</td></tr>";
}
function getname($id)
{
$result = mysql_query("select first_name,last_name from admin where id=$id");
$r = mysql_fetch_array($result);
return $r['first_name']." ".$r['last_name'];
}
?>
</table>
<br>
<textarea name="answer" rows="4" cols="50" required ></textarea>
<br>
<input type="Submit" value="Answer"/>
<button onclick="goBack()">Go Back</button>
<script>
function goBack() {
window.history.back();
}
</script>
</form>
<?php
$id = $_SESSION['id'];
if(isset($_REQUEST['answer']))
{
$q = "insert into answer (q_id,u_id,answer,datetime) values (".$_REQUEST['qid'].",".$id.",'".$_REQUEST['answer']."',CURRENT_TIMESTAMP)";
if(mysql_query($q))
{
echo "<script>
alert('New Answer inserted...');
</script>";
header('location:Answers.php?qid='.$_REQUEST['qid']);
}
else
{
echo "something wrong";
}
}
?>
<?php
include "footer.php";
?>