Question: in editing how can i make my php code works. below are my codings. when i click the edit post link, it should pass to

in editing how can i make my php code works. below are my codings. when i click the edit post link, it should pass to authenticate2.php first to key in username and password then if successful it will go to edit.php to grab the title and content that i want to edit. THere i can edit the post then when i click UPDATE button it should update the new edit post i did and will display in index.php. for delete button when i click the edit post link it will show the title and content message then when i click delete it will delete the post in the index.php.

heres my coding:

require('connect.php');

// UPDATE quote if author, content and id are present in POST. if ($_POST && isset($_POST['title']) && isset($_POST['content']) && isset($_POST['id'])) { // Sanitize user input to escape HTML entities and filter out dangerous characters. $title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $content = filter_input(INPUT_POST, 'content', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT); // Build the parameterized SQL query and bind to the above sanitized values. $query = "UPDATE blogs SET title = :title, content = :content WHERE id = :id"; $statement = $db->prepare($query); $statement->bindValue(':title', $title); $statement->bindValue(':content', $content); $statement->bindValue(':id', $id, PDO::PARAM_INT); // Execute the INSERT. $statement->execute((array(':title' => $title, ':content' => $content, ':id' => $id))); // Redirect after update. header("Location: index.php?id={$id}"); exit; } else if (isset($_GET['id'])) { // Retrieve quote to be edited, if id GET parameter is in URL. // Sanitize the id. Like above but this time from INPUT_GET. $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); // Build the parametrized SQL query using the filtered id. $query = "SELECT * FROM blogs WHERE id = :id"; $statement = $db->prepare($query); $statement->bindValue(':id', $id, PDO::PARAM_INT); // Execute the SELECT and fetch the single row returned. $statement->execute(); $blogs = $statement->fetch(); } else { $id = false; // False if we are not UPDATING or SELECTING. } ?>

Edit this Post!

Welcome to My Blog

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!