Skip to content
Snippets Groups Projects
Commit d4b5fcf3 authored by junchh's avatar junchh
Browse files

functionality pretty much okay

parent 00bb8baf
Branches
No related merge requests found
......@@ -8,17 +8,28 @@ if(!isset($_SESSION['user'])){
header('Location: login.php');
} else {
if(isset($_POST['submit']) && $_POST['content'] != ""){
if(isset($_POST['submit'])){
$text = $_POST['content'];
try {
$pdo->exec("INSERT INTO `message`(`timestamp`, `username`, `message`, `id_parent`) VALUES (NOW(), '" . $_SESSION['user']['username'] . "', '" . $text . "', '0')");
} catch(Exception $e){
exit($e);
}
if($_POST['bigpost'] == 1){
$text = $_POST['content'];
try {
$pdo->exec("INSERT INTO `message`(`timestamp`, `username`, `message`, `id_parent`) VALUES (NOW(), '" . $_SESSION['user']['username'] . "', '" . $text . "', '0')");
} catch(PDOException $e){
exit($e);
}
} else {
$text = $_POST['content2'];
try {
$pdo->exec("INSERT INTO `message`(`timestamp`, `username`, `message`, `id_parent`) VALUES (NOW(), '" . $_SESSION['user']['username'] . "', '" . $text . "', '" . $_POST['post_id'] . "')");
} catch(PDOException $e){
exit($e);
}
}
header ('Location: ' . $_SERVER['REQUEST_URI']);
exit();
}
}
......@@ -35,6 +46,7 @@ if(!isset($_SESSION['user'])){
<form action="index.php" method="POST">
<textarea name="content" rows="4" cols="50"></textarea>
<input type="submit" value="post" name="submit" />
<input type="hidden" name="bigpost" value="1"/>
</form>
<div class="posts">
<?php
......@@ -46,7 +58,25 @@ if(!isset($_SESSION['user'])){
<h2>' . $row['username'] . '</h2>
<h3>' . $row['timestamp'] . '</h3>
<p>' . $row['message'] . '</p>
</div>
</div>';
$query2 = $pdo->query("SELECT * FROM `message` WHERE `id_parent` = '" . $row['id'] . "' ORDER BY `id` ASC");
$rows2 = $query2->fetchAll(PDO::FETCH_ASSOC);
echo '<div style="background-color: gray;" class="replies">';
foreach($rows2 as $row2){
echo '<div class="reply">
<h2>' . $row2['username'] . '</h2>
<h3>' . $row2['timestamp'] . '</h3>
<p>' . $row2['message'] . '</p>
</div>
';
}
echo '</div>
<form action="index.php" method="POST">
<input type="hidden" name="post_id" value="' . $row['id'] . '"/>
<textarea name="content2" rows="2" cols="30"></textarea>
<input type="submit" value="reply" name="submit" />
</form>
';
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment