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. } ?>
Welcome to My Blog
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started