Files
tinytalkhub/index.php
2023-12-04 19:38:55 +01:00

55 lines
1.9 KiB
PHP

<?php
include "connectionDB.php";
include "checkUser.php";
if($_SERVER["REQUEST_METHOD"] === "POST") {
if($_POST["content"] !== "" && strlen($_POST["content"]) < 451) {
$add_post->execute(array($_POST["content"], $_COOKIE["userID"]));
}
}
if(!isset($_COOKIE["user"])) {
header("Location: /auth.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TinyTalkHub</title>
<link rel="stylesheet" href="css/global.css">
<link rel="icon" type="image/x-icon" href="/favicon-32x32.png">
</head>
<body>
<h1><a href="/index.php">TinyTalkHub</a></h1>
<div class="form-wrap-post">
<form action="/" method="POST" >
<textarea maxlength="450" name="content" placeholder="Your message"></textarea>
<input name="autor_id" value="<?php echo $_COOKIE["userID"] ?>" type="hidden"></input>
<button>Submit</button>
</form>
<a href="/exit.php">Logout from site</a>
</div>
<div>
<?php
$posts = $pdo->query($get_posts_query);
?>
<?php foreach($posts->fetchAll() as $row) { ?>
<div class="wrap-posts">
<div class="wrap-post-info">
<img src="<?php echo $row["avatar_url"] ?>" alt="avatart" class="avatar"></img>
<a href="/profile.php?id=<?php echo $row["autor_id"] ?>">
Created by <?php echo $row["username"] ?>
</a>
<p> <?php echo $row["date"] ?>
</p>
</div>
<div class="wrap-post-content">
<p> <?php echo $row["content"] ?></p>
</div>
</div>
<?php }?>
</div>
</body>
</html>