The following files exists in this folder. Click to view.
newpost.php67 lines UTF-8 Unix (LF) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
<?php
include("check_session.php");
require_once('databaseconnection.php');
$sql = "SELECT `blogId` FROM manage WHERE `userId` = :userId";
$stm = $pdo->prepare($sql);
$stm->execute(['userId' => $_SESSION["userId"]]);
$blogIdArray = $stm->fetchAll(PDO::FETCH_COLUMN); #Hämta alla Id på bloggar skapade utav dig
if (!empty($blogIdArray)){ #stoppar nedanstående SQL från att köras om användaren inte har några bloggar. (stoppar error)
$placeholders = implode(',', array_fill(0, count($blogIdArray), '?'));
$sql = "SELECT `name` FROM blog WHERE `blogId` IN ($placeholders)"; #tar alla namn på bloggar som användaren har tillgång till.
$stm = $pdo->prepare($sql);
$stm->execute($blogIdArray);
$dbOutput = $stm->fetchAll(PDO::FETCH_COLUMN);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New post</title>
<link rel="stylesheet" href="/spectre/spectre-master/dist/spectre.css">
<script src="https://kit.fontawesome.com/0b0c9a8dc7.js" crossorigin="anonymous"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Special+Gothic+Expanded+One&family=Special+Gothic:wght@400..700&display=swap" rel="stylesheet">
<style>
#navTop{
font-family: "Special Gothic Expanded One", Helvetica;
}
</style>
</head>
<body style="text-align: center;">
<header class="navbar">
<section class="navbar-section">
<a href="settings.php" class="btn btn-link">Settings</a>
<a href="home.php" class="btn btn-link">Home</a>
</section>
<section class="navbar-center">
<h3 id="navTop">PHiNTERNET</h3>
</section>
<section class="navbar-section">
<a href="#" class="btn btn-link">Create Post</a>
<a href="profile.php?mess=<?php echo"{$_SESSION["userId"]}"?>" class="btn btn-link">Profile</a>
</section>
</header>
<h1>Choose blog</h1>
<a class="btn btn-primary" href="newblog.php">New Blog</a>
<br><br><br>
<form method="post" action="post_create.php">
<?php
if (isset($dbOutput)){
for ($i=0; $i<= count($dbOutput)-1; $i++){
echo"<a style=\"margin:0.2rem;\" class=\"btn\" href=\"h_blog_insert.php?mess={$blogIdArray[$i]}|{$dbOutput[$i]}\">{$dbOutput[$i]}</a>"; #skriv ut alla bloggar som knappar
}
}
?>
</form>
</body>
</html>