Currently I'm trying to create a news system where I write an article using ckeditor and after I publish it, the field saves the inputs in a mysql table, displaying the published news at the index page. I'm able to fetch the data so that it can be displayed at the index page and it works. This is how I do it:
<div class="panel-body">
<?php
$db = getDB();
$stmt = $db->prepare("SELECT * FROM news ORDER BY created_at DESC;");
$stmt->execute();
while($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
$title = $data['title'];
$content = $data['content'];
$date = $data['created_at'];
$admin = (int)$data['admin'];
$id = (int)$data['id'];
$admin_data = new User($admin);
$admin_name = $admin_data->getUsername();
print("<div class='timeline-panel'>");
print("<div class='timeline-heading'>");
print ("<h4 class='timeline-title'><b>$title</b></h4>");
print ("<p><small class='text-muted'><i class='fa fa-clock-o'></i> $date $admin_name</small></p>");
print("</div>");
print("<div class='timeline-body'>");
print("<p>$content</p>");
print("</div>");
print("</div>");
print("</li>");
print("<hr style='height:1px;border-top:2px solid #aa0000'>");
}
?>
</div>
Now for being able to publish the news, I tried utilizing ckeditor and drafted this but it does not save the values in the fields at all.;
<script src="/ugrp/ckeditor/ckeditor.js"></script>
<div id="wrapper">
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
</div>
<!-- /.col-lg-12 -->
</div>
<div class="col-md-12" style="padding: 20px 15px;">
<?php
if(isset($_POST['submit'])) {
$db = getDB();
$stmt = $db->prepare("INSERT INTO `news`(`id`, `admin`, `content`, `title`, `created_at`) VALUES (:title, :content, :created_at, :admin, :id)");
$stmt->bindParam('title', $title, PDO::PARAM_STR);
$stmt->bindParam('content', $content, PDO::PARAM_INT);
$stmt->bindParam('created_at', $created_at, PDO::PARAM_INT);
$stmt->bindParam('admin', $admin, PDO::PARAM_INT);
$stmt->bindParam('id', $id, PDO::PARAM_INT);
$stmt->execute();
}
?>
<form>
<div class="form-group">
<input name="title" type="text" id="title" class="form-control" placeholder="Title of the News"><br>
</div>
<div class="form-group">
</div>
<textarea name="content" id="content">
</textarea>
<script>
CKEDITOR.replace( 'content' );
</script>
<center><button type="submit" name="submit" class="btn bg-red btn-block"><i class="fa fa-pencil"></i> Submit</button></center>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
All I want is to be able to publish the news which would save in the table mentioned above in the code.
I'm sure I have made a lot of mistakes in the publishing code, which is why any help would be appreciated.
This is what it looks like when it displays the news at the index page. NOTE: The values seen in the picture were added manually in the table.