Can you help me here to find what is wr The time , dosn't work , it show 0000. 00 . 00 As in picture I attached with the question. Here the code for class and follow for the main. php
Can you help me here to find what is wr
The time , dosn't work , it show 0000. 00 . 00 As in picture I attached with the question.
Here the code for class and follow for the main.
<?php
//include("includes/config.php");
class Posts {
private $db;
// This __construct function I use to open up a connection to my
function __construct() {
$this->db = new mysqli(DBHOST, DBUSER, DBPASS, DBDATABASE);
if($this->db->connect_errno > 0) {
die("Connection error: " . $db->connect_error);
}
}
// My method to read posts from my database
public function getPosts() {
// sql command to get data from my database table called 'guestbook'
$sql = "SELECT * from guestbook /*ORDER BY created DESC*/";
$result = $this->db->query($sql);
return mysqli_fetch_all($result, MYSQLI_ASSOC);
}
public function addPost(string $user, string $content, $created ) {
$created =date("M-d-Y h:i:s A");
$sql = "INSERT INTO guestbook(user, content, created)VALUES('$user', '$content','$created')";
return $this->db->query($sql);
}
public function deletePost(int $id) {
$sql = "DELETE FROM guestbook WHERE id=$id";
return $this->db->query($sql);
}
}
The secound:
<?php $page_title = "Visitors's GuestBook"; ?>
<?php include("includes/header.php"); ?>
<?php include("includes/mainmenu.php"); ?>
<article class="mainContent">
<?php echo "<h1>$page_title</h1><br/>"; ?>
<article class="guestbook-container">
<div class="left-flexbox">
<?php
$post = new Posts();
// add post to my guestbook
if(isset($_POST['user'])) {
$user = $_POST['user'];
$content = $_POST['content'];
$created = $_POST['created'];
$post->addPost($user, $content, $created);
header("Location: part2.php");
}
?>
<h3>Leave A Comment!</h3>
<form action="part2.php" method="post">
<label for="user">Your Name: </label>
<input type="text" name="user" id="user">
<br/>
<br/>
<label for="content"> Your Comment:</label>
<textarea class="textrutan-message" name="content" id="content" rows="10" cols="30"></textarea>
<br/><br/>
<input type="submit" name="postMessage" value="Submit Your Post"><br/>
</form>
</div>
<div class="right-flexbox">
<?php
$guestbookitems = $post->getPosts();
foreach($guestbookitems as $item) {
echo "<div class='div-containing-message'><h3>" . $item['user'] . "</h3>";
echo "<p>" . $item['content'] . "</p>";
echo "<h4>" . $item['created'] . "</h4></div>";
}
?>
</div>
</article> </article>
<?php include("includes/footer.php"); ?>
Step by step
Solved in 2 steps