Good day mga master
Pahelp sana sa pag handle ng line breaks sa PHP
Hindi gumagana yung nl2br() kahit sa controller at model ilagay, kahit pati sa frontend.
Output:
Code sa ui/view:
Code sa controller:
Code sa model
Side project lang mga idol, sana may makatulong. Salamat and god bless
Pahelp sana sa pag handle ng line breaks sa PHP
Hindi gumagana yung nl2br() kahit sa controller at model ilagay, kahit pati sa frontend.
Output:
Code sa ui/view:
PHP:
<p>
<?php $formattedComment = nl2br($comment['comment_text']);
var_dump($formattedComment);
?>
</p>
Code sa controller:
PHP:
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["addComment"])) {
$post_id = $_POST['post_id'];
$user_id = $_POST['user_id'];
$comment_text = $_POST['commentContent'];
$status = $postController->addComment($post_id, $user_id, $comment_text);
if ($status) {
header("Location: view-post.php?action=view-post&id=$post_id");
exit;
} else {
header("Location: view-post.php?action=view-post&id=$post_id&error=comment_failed");
}
}
PHP:
public function addComment($post_id, $user_id, $comment_text) {
$comment_text = $this->postModel->sanitizeCommentText($comment_text);
$status = $this->postModel->addComment($post_id, $user_id, $comment_text);
if($status) {
return true;
} else {
return false;
}
}
Code sa model
PHP:
public function addComment($post_id, $user_id, $comment_text) {
$currentTimestamp = time();
$formattedDateTime = date('Y-m-d H:i:s', $currentTimestamp);
$comment_text = $this->conn->real_escape_string($comment_text);
$sql = "INSERT INTO tbl_comments (post_id, user_id, comment_text, comment_date) VALUES (?, ?, ?, ?)";
$stmt = $this->conn->prepare($sql);
$stmt->bind_param("iiss", $post_id, $user_id, $comment_text, $formattedDateTime);
if ($stmt->execute()) {
return true;
} else {
return false;
}
}
Side project lang mga idol, sana may makatulong. Salamat and god bless
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.