EDIT: I've coded a blog, and I want to be able to edit entries. A blog entry will have id, title, message, and date_added. I want the id to stay consistent when there has been an edit, so if you edit blog entry id 1, the updated version will also be id 1. I've got the following code, but it keeps throwing an error saying that it can't do it because there's a duplicate entry with the same id. This is my code:
ManagerMessage
PHP Code:
require_once("Manager.php");
class ManagerMessage extends Manager { static $edit_message = "INSERT INTO messages(id,title,message,date_added) values(?,?,?,?)";
function doExecute(Request $request) { // Get data from request $id = $request->getProperty('editid'); $title = $request->getProperty('edittitle'); $message = $request->getProperty('editmessage');
// Create manager object $manager = new ManagerMessage();
// Add to database $manager->editMessage($title, $message, $id);
// Redirect to index header("location:blog.php"); } }
Thanks for your reply. I forgot to mention that I'm implementing versioning, so I don't actually want to update, but insert the editted entry, and then move the old version to a different table.
Your database isn't going to let you do that. It sounds like you have the id field set appropriately as unique, possibly primary.
If you want to store revision within the same table, you'll need to edit that table config to remove the unique/primary from the field. Once you do that, you'll need to add some extra complexity to your blog post listing logic in order to pull out only the desired version.
An ideal system would probably separate revision storage from the master post storage. It would also add complexity, but would allow for cleanly separated data.
EDIT: I just read your last post again and understand now what you're saying. It still won't work for the previously mentioned reasons. But you probably can't just move/delete the old post and then add the revision. Depends on the id field.
Thanks for your reply. I forgot to mention that I'm implementing versioning, so I don't actually want to update, but insert the editted entry, and then move the old version to a different table.
You're doing it the wrong way around. Copy the existing version to the other table and then update the existing record with the new entry.