-
Notifications
You must be signed in to change notification settings - Fork 0
/
discussionreply.php
150 lines (146 loc) · 4.78 KB
/
discussionreply.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
<?php
include("header.php");
if($_SESSION[sessionid] == $_POST[sessionid])
{
if($_FILES["uploads"]["name"] != "")
{
$imgname = rand(). $_FILES["uploads"]["name"];
move_uploaded_file($_FILES["uploads"]["tmp_name"],"discussionreplyimages/".$imgname);
}
if(isset($_POST[submit]))
{
if(isset($_GET[editid]))
{
$sql="UPDATE discussion_reply set discussion_id=$_POST[discussiontitle],student_id=$_SESSION[student_id],user_id=$_SESSION[user_id],message=$_POST[message],";
if($_FILES["uploads"]["name"] != "")
{
$sql = $sql . "uploads=$imgname,";
}
$sql = $sql .
"date_time=$dt $tim WHERE discussion_reply_id=$_GET[editid]";
$qsql = mysqli_query($con,$sql);
if(!$qsql)
{
echo mysqli_error($con);
}
if(mysqli_affected_rows($con) == 1)
{
echo "<SCRIPT>alert(Discussion reply record UPDATED successfully..);</SCRIPT>";
}
}
else
{
$sql="INSERT INTO discussion_reply(discussion_id,student_id,user_id,message,uploads,date_time) values ($_POST[discussiontitle],$_SESSION[student_id],$_SESSION[user_id],$_POST[message],$imgname,$dt $tim)";
$qsql = mysqli_query($con,$sql);
if(!$qsql)
{
echo mysqli_error($con);
}
if(mysqli_affected_rows($con) == 1)
{
echo "<SCRIPT>alert(Discussion reply record inserted successfully);</SCRIPT>";
}
}
}
}
$_SESSION[sessionid] = rand();
if(isset($_GET[editid]))
{
$sqledit = "SELECT * FROM discussion_reply WHERE discussion_reply_id=$_GET[editid]";
$qsqledit = mysqli_query($con,$sqledit);
$rsedit = mysqli_fetch_array($qsqledit);
}
?>
<section id="contentSection">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">
<div class="left_content">
<div class="contact_area">
<h2>Discussion Reply</h2>
<p>Add your replies.</p>
<form action="" class="contact_form" method="post" enctype="multipart/form-data" name="frmdiscussionreply" onsubmit="return validateform()" >
<input type="hidden" name="sessionid" value="<?php echo $_SESSION[sessionid]; ?>" >
Discussion Title:
<select name="discussiontitle" class="form-control" >
<option value="">Select Title</option>
<?php
$sqldiscussion = "SELECT * FROM discussion WHERE status=Active";
$qsqldiscussion = mysqli_query($con,$sqldiscussion);
while($rsdiscussion = mysqli_fetch_array($qsqldiscussion))
{
if($rsdiscussion[discussion_id] == $rsedit[discussion_id])
{
echo "<option value=$rsdiscussion[discussion_id] selected>$rsdiscussion[discussion_title]</option>";
}
else
{
echo "<option value=$rsdiscussion[discussion_id]>$rsdiscussion[discussion_title]</option>";
}
}
?>
</select>
<span id="iddiscussiontitle"></span>
<br />
Message:
<textarea name="message" class="form-control" cols="30" rows="10" placeholder="message *"><?php echo $rsedit[message]; ?></textarea>
<span id="idmessage"></span>
<br>
Uploads:
<input type="file" name="uploads" class="form-control" value="<?php echo $rsedit[uploads]; ?>" accept="image/*" onchange="loadFile(event)">
<?php
if($rsedit[uploads] == "")
{
echo <img src="images/no-image.png" height="200" alt="Image preview..." id="previewimg">;
}
else
{
echo "<img src=discussionreplyimages/$rsedit[uploads] height=200 alt=Image preview... id=previewimg>";
}
?>
<br />
<input name="submit" type="submit" value="submit">
</form>
</div>
</div>
</div>
</div>
</section>
<?php
include("footer.php")
?>
<script>
var loadFile = function(event) {
var reader = new FileReader();
reader.onload = function(){
var output = document.getElementById(previewimg);
output.src = reader.result;
};
reader.readAsDataURL(event.target.files[0]);
};
</script>
<script type="application/javascript">
function validateform()
{
var validatecondtion = 0;
document.getElementById("iddiscussiontitle").innerHTML ="";
document.getElementById("idmessage").innerHTML ="";
if(document.frmdiscussionreply.discussiontitle.value=="")
{
document.getElementById("iddiscussiontitle").innerHTML ="<font color=red>Kindly select discussion title..</font>";
validatecondtion=1;
}
if(document.frmdiscussionreply.message.value=="")
{
document.getElementById("idmessage").innerHTML ="<font color=red>Message cannot be empty...</font>";
validatecondtion=1;
}
if(validatecondtion==1)
{
return false;
}
else
{
return true;
}
}
</script>