-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replies implementation(tested on local machine)
Changed the icon directory(now under main directory) To do list: -stuff in comment.php aren't exactly aligned
- Loading branch information
1 parent
324c6ab
commit 5e93388
Showing
8 changed files
with
244 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
include_once 'header.php'; | ||
echo "<br>"; | ||
if(isset($_POST['view_reply_parent'])) | ||
{ | ||
$_SESSION['view_reply_parent'] = $_POST['view_reply_parent']; | ||
} | ||
$parent_id = $_SESSION['view_reply_parent']; | ||
if(isset($_POST['submit_comment'])) | ||
{ | ||
try | ||
{ | ||
$uid = $_SESSION['user']; | ||
$msg = $_POST['comment']; | ||
$time = date('Y/m/d H:i:s'); | ||
$insert = "INSERT INTO comments(cmt,uid,cmt_time,parent_id) VALUES(?,?,?,?)"; | ||
$stmt = $conn->prepare($insert); | ||
$stmt->bindValue(1,$msg); | ||
$stmt->bindValue(2,$uid); | ||
$stmt->bindValue(3,$time); | ||
$stmt->bindValue(4,$parent_id); | ||
$stmt->execute(); | ||
?> | ||
<script>alert('successfully sent reply');</script> | ||
<?php | ||
echo "<meta http-equiv='refresh' content='0'>";//refresh the page | ||
} | ||
catch(Exception $e) | ||
{ | ||
die(var_dump($e)); | ||
} | ||
} | ||
|
||
//display the parent message | ||
$sql_select = "SELECT msg_id,msg, username,msg_time,uid | ||
FROM messages, users | ||
WHERE messages.uid = users.user_id AND messages.msg_id = $parent_id"; | ||
$res=$conn->prepare($sql_select); | ||
$res->execute(); | ||
?> | ||
<table class = "table-fill"> | ||
<tr><th>Message</th> | ||
<th>By</th> | ||
<th>Time</th> | ||
<?php | ||
while($row=$res->fetch(PDO::FETCH_OBJ)) | ||
{ | ||
echo "<tr><td>".$row -> msg."</td>"; | ||
echo "<td>".$row -> username."</td>"; | ||
echo "<td>".$row -> msg_time."</td>"; | ||
echo "</tr>"; | ||
} | ||
echo "</table><br>"; | ||
|
||
//display the replys to that message | ||
|
||
$sql_select = "SELECT cmt,cmt_id,username,cmt_time | ||
FROM comments | ||
INNER JOIN messages ON $parent_id=comments.parent_id AND parent_id = messages.msg_id | ||
INNER JOIN users ON users.user_id = comments.uid | ||
ORDER BY cmt_time DESC "; | ||
$res=$conn->prepare($sql_select); | ||
$res->execute(); | ||
if($res->rowCount()!=0) | ||
{ | ||
?> | ||
<table class = "table-fill"> | ||
<tr><th>Replies</th> | ||
<th>By</th> | ||
<th>Time</th> | ||
<?php | ||
while($row=$res->fetch(PDO::FETCH_OBJ)) | ||
{ | ||
echo "<tr><td>".$row -> cmt."</td>"; | ||
echo "<td>".$row -> username."</td>"; | ||
echo "<td>".$row -> cmt_time."</td>"; | ||
echo "</tr>"; | ||
} | ||
echo "</table>"; | ||
} | ||
else | ||
{ | ||
echo "<div class='table-title'>"; | ||
echo "<h3>No replies here</h3>"; | ||
echo "</div>"; | ||
} | ||
?> | ||
<form action="comment.php" method="POST"> | ||
<input type="hidden" name="submit_comment" value="1" /> | ||
<?php echo "<input type='hidden' name='view_reply_parent' value=".$_SESSION['view_reply_parent'].">"; ?> | ||
<textarea name="comment" id = 'msg'></textarea><br /> | ||
<button type="submit" id ='msg_submit'>Submit reply to this message</button> | ||
</form> | ||
<br> | ||
<a href="home.php" id="back_to_home">Go Back</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
session_start(); | ||
include_once 'dbconnect.php'; | ||
if(!isset($_SESSION['user'])) | ||
{ | ||
header("Location: index.php"); | ||
} | ||
?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>Welcome - <?php echo $userRow['email']; ?></title> | ||
<link rel="stylesheet" href="style.css" type="text/css" /> | ||
</head> | ||
<body> | ||
<div id="header"> | ||
<div id="left"> | ||
<label>410221009 DBMS final project</label> | ||
</div> | ||
<div id="right"> | ||
<div id="content"> | ||
hi' <?php echo $_SESSION['username'];?> <a href="logout.php?logout">Sign Out</a> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.