WRITE YOUR (Web hosting account) OWN BLOG ENGINE
WRITE YOUR OWN BLOG ENGINE
And this: If you now enter http://127.0.0.1/cms/addpost.php?post_id=1 into your browser, the form should populate with the first post you added. However the submit button will still say Add a post (and if you click it, that s exactly what will happen you will get a second post identical to the first, but with a post_id of 2). To deal with this, I will introduce case switching in PHP. Replace the submit button with this code: “; echo ““; break; case false: echo ““; break; } ?> The switch statement is similar to a series of if statements on the same expression. On many occasions, you might want to compare the same variable with many different values and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for. In this case, you are echoing a different submit button depending on the value of $editmode. You can apply a similar approach to the title and heading of your page. Note that I have also added a hidden form field to the Update post button so the form also submits the post_id of the current post. The script will then know which post to update. And finally the SQL script to update the post. Insert this code just after where you set $editmode=true: // If form has been submitted, update post if (isset($_POST[”submitUpdate”])) { $sql = “UPDATE posts SET title=’$db_title’, postdate=’$db_postdate’, 287