Is it recommended to create a new record in a separate table when editing comments in a PHP application?
When editing comments in a PHP application, it is not recommended to create a new record in a separate table. Instead, you should update the existing record in the database to reflect the changes made to the comment. This ensures that the comment history is maintained and that the original comment can be referenced if needed.
// Update comment in database
$commentId = $_POST['comment_id'];
$newComment = $_POST['new_comment'];
$sql = "UPDATE comments SET comment = :new_comment WHERE id = :comment_id";
$stmt = $pdo->prepare($sql);
$stmt->execute(['new_comment' => $newComment, 'comment_id' => $commentId]);
Related Questions
- Are there any potential pitfalls to be aware of when using a loop to generate time intervals in PHP, especially when dealing with the "60 minutes" boundary?
- What are some potential reasons why the PHP cookie with expires 0 is not working on mobile devices?
- What are the best practices for iterating through database query results and assigning them to JavaScript variables in PHP?