title
Learn PHP: Basic CMS - Editing Pages (Part 7/8)
description
Want more? Explore the library at https://www.codecourse.com/lessons
Official site
https://www.codecourse.com
Twitter
https://twitter.com/teamcodecourse
detail
{'title': 'Learn PHP: Basic CMS - Editing Pages (Part 7/8)', 'heatmap': [], 'summary': 'Tutorial covers the process of linking an edit page, passing data through urls, modifying data, checking and retrieving database records, handling form submissions, and updating page data with prepared statements in php, demonstrating specific ids and generating urls.', 'chapters': [{'end': 133.149, 'segs': [{'end': 26.034, 'src': 'embed', 'start': 0.329, 'weight': 0, 'content': [{'end': 7.957, 'text': 'To start off editing a page, we need to hook up this link so we can click it and then go through to an edit page,', 'start': 0.329, 'duration': 7.628}, {'end': 15.325, 'text': 'passing in the page that we want to edit, grab that data and insert it into the form ready to be modified.', 'start': 7.957, 'duration': 7.368}, {'end': 18.469, 'text': 'So it sounds a little bit more complicated than it actually is.', 'start': 15.886, 'duration': 2.583}, {'end': 20.33, 'text': "But let's start out with this link.", 'start': 18.889, 'duration': 1.441}, {'end': 26.034, 'text': 'So remember over on our list.php page, we have this edit link just here.', 'start': 21.171, 'duration': 4.863}], 'summary': 'Instructions to link and edit a page for modification in php.', 'duration': 25.705, 'max_score': 0.329, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8329.jpg'}, {'end': 91.507, 'src': 'embed', 'start': 53.892, 'weight': 1, 'content': [{'end': 59.073, 'text': 'And then what we want to do is we want to specify an ID in the query string.', 'start': 53.892, 'duration': 5.181}, {'end': 67.295, 'text': "So let's go and echo out page ID.", 'start': 59.793, 'duration': 7.502}, {'end': 71.976, 'text': 'And again, we will escape that.', 'start': 68.535, 'duration': 3.441}, {'end': 75.633, 'text': 'So now we can click this.', 'start': 73.911, 'duration': 1.722}, {'end': 83.6, 'text': 'We go through to edit.php with an ID of three for this record here, for this one ID of one, for this one ID of two.', 'start': 75.913, 'duration': 7.687}, {'end': 89.025, 'text': 'So what we can now do then is create our edit page.', 'start': 84.741, 'duration': 4.284}, {'end': 91.507, 'text': 'So under admin, we create a new file.', 'start': 89.145, 'duration': 2.362}], 'summary': 'Creating an edit page under admin with specified ids for records.', 'duration': 37.615, 'max_score': 53.892, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U853892.jpg'}], 'start': 0.329, 'title': 'Editing page link and data insertion', 'summary': 'Explains the process of hooking up a link to an edit page, passing data through url, and creating an edit page to modify data, demonstrating how to pass specific ids and generate urls.', 'chapters': [{'end': 133.149, 'start': 0.329, 'title': 'Editing page link and data insertion', 'summary': 'Explains the process of hooking up a link to an edit page, passing data through url, and creating an edit page to modify data, demonstrating how to pass specific ids and generate urls.', 'duration': 132.82, 'highlights': ['The process involves hooking up a link to an edit page, passing in the page ID through the URL, and creating an edit page to modify the data, showcasing the generation of specific URLs and data insertion.', 'The chapter demonstrates the steps to redirect users to the edit page by passing the page ID through the URL and creating an edit.php file to handle the modification of data.', 'Detailing the process of creating an edit page and passing specific IDs through the URL to modify data, showcasing the steps to hook up a link and generate URLs.']}], 'duration': 132.82, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8329.jpg', 'highlights': ['The process involves hooking up a link to an edit page, passing in the page ID through the URL, and creating an edit page to modify the data, showcasing the generation of specific URLs and data insertion.', 'The chapter demonstrates the steps to redirect users to the edit page by passing the page ID through the URL and creating an edit.php file to handle the modification of data.', 'Detailing the process of creating an edit page and passing specific IDs through the URL to modify data, showcasing the steps to hook up a link and generate URLs.']}, {'end': 483.099, 'segs': [{'end': 188.192, 'src': 'embed', 'start': 134.229, 'weight': 0, 'content': [{'end': 147.935, 'text': 'Brilliant. So the next thing to do, then, is to actually check if we have that ID in the query string and go ahead and pull that record from the database,', 'start': 134.229, 'duration': 13.706}, {'end': 150.337, 'text': 'passing in the ID, so we only get that one record.', 'start': 147.935, 'duration': 2.402}, {'end': 157.871, 'text': "So instead we're going to take a little bit of a different approach and we're going to check if the ID isn't there.", 'start': 151.727, 'duration': 6.144}, {'end': 169.018, 'text': "So we're going to use is set and we're going to say if it's not set, get because remember we're pulling it from the query string and then ID.", 'start': 158.692, 'duration': 10.326}, {'end': 178.785, 'text': "So all that's saying is if this ID doesn't exist in the query string, we want to go ahead and redirect the user off somewhere.", 'start': 169.799, 'duration': 8.986}, {'end': 188.192, 'text': "So we're going to redirect them to base URL, and then we're going to append on admin list.php.", 'start': 180.53, 'duration': 7.662}], 'summary': 'Check query string for id, if not redirect to base url.', 'duration': 53.963, 'max_score': 134.229, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8134229.jpg'}, {'end': 335.407, 'src': 'embed', 'start': 237.521, 'weight': 2, 'content': [{'end': 248.451, 'text': 'We can go ahead and execute that passing in ID and we can pass in dollar underscore get ID in there.', 'start': 237.521, 'duration': 10.93}, {'end': 250.793, 'text': 'And then that will give us our page.', 'start': 249.391, 'duration': 1.402}, {'end': 252.834, 'text': 'So we just need to fetch it now.', 'start': 251.513, 'duration': 1.321}, {'end': 258.099, 'text': "So we do exactly as we've done before PDO.", 'start': 255.617, 'duration': 2.482}, {'end': 262.781, 'text': 'fetch associative array.', 'start': 260.399, 'duration': 2.382}, {'end': 273.17, 'text': 'So if we do var dump on page, we should see now that particular page.', 'start': 264.422, 'duration': 8.748}, {'end': 277.033, 'text': 'So third page, second page and first page.', 'start': 273.19, 'duration': 3.843}, {'end': 279.595, 'text': "So let's go ahead and edit the first page then.", 'start': 277.573, 'duration': 2.022}, {'end': 290.686, 'text': 'So all we want to do now then is we have this page variable and this will automatically be available in our edit view.', 'start': 281.5, 'duration': 9.186}, {'end': 293.048, 'text': 'So we just need to build up our form.', 'start': 290.706, 'duration': 2.342}, {'end': 301.393, 'text': 'To save a little bit of time, we can copy and paste the add form that we created because all we need is the same form.', 'start': 293.988, 'duration': 7.405}, {'end': 305.136, 'text': 'We just need to output the existing values into these inputs.', 'start': 301.413, 'duration': 3.723}, {'end': 309.879, 'text': "So I'm going to copy this entire page here and I'm going to put it into edit.", 'start': 305.176, 'duration': 4.703}, {'end': 315.204, 'text': "I'm going to change this to edit page.", 'start': 311.56, 'duration': 3.644}, {'end': 319.509, 'text': "We're going to change the action on the form to edit.", 'start': 316.366, 'duration': 3.143}, {'end': 321.672, 'text': "We don't want to submit this back through to add.", 'start': 319.569, 'duration': 2.103}, {'end': 324.975, 'text': 'And that is pretty much it.', 'start': 323.033, 'duration': 1.942}, {'end': 327.198, 'text': 'I suppose we can change the submit button as well.', 'start': 325.076, 'duration': 2.122}, {'end': 332.146, 'text': 'So now when we edit a page, we end up with this.', 'start': 328.624, 'duration': 3.522}, {'end': 335.407, 'text': 'All we need to do is fill in this data.', 'start': 333.086, 'duration': 2.321}], 'summary': 'Executing code to fetch and edit pages, copying and pasting form for efficiency.', 'duration': 97.886, 'max_score': 237.521, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8237521.jpg'}, {'end': 453.098, 'src': 'embed', 'start': 399.028, 'weight': 4, 'content': [{'end': 400.409, 'text': 'We can just change that to label.', 'start': 399.028, 'duration': 1.381}, {'end': 402.81, 'text': "We'll do the same thing for slug.", 'start': 401.369, 'duration': 1.441}, {'end': 406.548, 'text': 'And our text area is slightly different.', 'start': 404.827, 'duration': 1.721}, {'end': 408.289, 'text': "We don't have a value attribute here.", 'start': 406.568, 'duration': 1.721}, {'end': 414.173, 'text': 'So what we want to do is instead echo page body.', 'start': 408.97, 'duration': 5.203}, {'end': 418.896, 'text': 'We still want to escape this like so.', 'start': 414.193, 'duration': 4.703}, {'end': 421.277, 'text': 'And we end up with the following.', 'start': 420.036, 'duration': 1.241}, {'end': 423.158, 'text': "So we've got all the information that we need.", 'start': 421.457, 'duration': 1.701}, {'end': 428.262, 'text': 'The last thing to do is create a hidden input field down here.', 'start': 424.279, 'duration': 3.983}, {'end': 430.906, 'text': 'And that will allow us to output the ID.', 'start': 429.025, 'duration': 1.881}, {'end': 441.612, 'text': "When we submit the form, we'll have that available in our post super global, ready to edit our page only where the ID equals this ID.", 'start': 431.606, 'duration': 10.006}, {'end': 445.734, 'text': 'So we have an input of type hidden.', 'start': 442.893, 'duration': 2.841}, {'end': 447.475, 'text': "So this isn't shown to the user.", 'start': 445.994, 'duration': 1.481}, {'end': 450.337, 'text': 'We can give this a name of ID.', 'start': 448.796, 'duration': 1.541}, {'end': 453.098, 'text': 'So we know how to pick that up in our post super global.', 'start': 450.577, 'duration': 2.521}], 'summary': 'Changing label and slug, echoing page body, creating hidden input field for id.', 'duration': 54.07, 'max_score': 399.028, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8399028.jpg'}], 'start': 134.229, 'title': 'Php database record retrieval and editing page forms', 'summary': 'Discusses checking and retrieving a specific database record using php, handling non-existent ids, redirecting users, and preparing and executing sql statements with placeholders. it also explains editing page forms by populating existing values, creating a hidden input field to specify the id for updating, and outputting initial values such as title, label, slug, and body.', 'chapters': [{'end': 277.033, 'start': 134.229, 'title': 'Php database record retrieval', 'summary': 'Discusses checking and retrieving a specific database record using php, including handling non-existent ids, redirecting users, and preparing and executing sql statements with placeholders.', 'duration': 142.804, 'highlights': ["The chapter explains the process of checking if a specific ID exists in the query string and pulling the corresponding record from the database, redirecting users if the ID doesn't exist, and preparing and executing SQL statements with placeholders to retrieve the desired page.", 'The approach involves using is set to check if the ID exists in the query string, redirecting the user to the base URL appended with admin list.php if the ID is absent, and terminating the page execution, ensuring redirection to the list page if no ID is present.', 'The process of preparing a statement to select specific fields from the database, executing the statement with the passed-in ID, and fetching the retrieved page using PDO fetch associative array is detailed, providing insights into the retrieval of database records based on the provided ID.']}, {'end': 483.099, 'start': 277.573, 'title': 'Editing page forms and values', 'summary': 'Explains how to edit page forms by populating existing values, including creating a hidden input field to specify the id for updating, and outputting initial values such as title, label, slug, and body.', 'duration': 205.526, 'highlights': ['The chapter covers editing page forms by populating existing values, including creating a hidden input field to specify the ID for updating.', 'It explains how to output initial values such as title, label, slug, and body, utilizing value attributes and escaping the values to prevent security risks.', 'The process involves copying the add form, changing the action to edit, and adjusting the submit button.', "The form includes a hidden input field with the name 'ID' and the value as the page ID, which is escaped to prevent security risks."]}], 'duration': 348.87, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8134229.jpg', 'highlights': ["The chapter explains the process of checking if a specific ID exists in the query string and pulling the corresponding record from the database, redirecting users if the ID doesn't exist, and preparing and executing SQL statements with placeholders to retrieve the desired page.", 'The approach involves using isset to check if the ID exists in the query string, redirecting the user to the base URL appended with admin list.php if the ID is absent, and terminating the page execution, ensuring redirection to the list page if no ID is present.', 'The process of preparing a statement to select specific fields from the database, executing the statement with the passed-in ID, and fetching the retrieved page using PDO fetch associative array is detailed, providing insights into the retrieval of database records based on the provided ID.', 'The chapter covers editing page forms by populating existing values, including creating a hidden input field to specify the ID for updating.', 'It explains how to output initial values such as title, label, slug, and body, utilizing value attributes and escaping the values to prevent security risks.', 'The process involves copying the add form, changing the action to edit, and adjusting the submit button.', "The form includes a hidden input field with the name 'ID' and the value as the page ID, which is escaped to prevent security risks."]}, {'end': 787.033, 'segs': [{'end': 546.452, 'src': 'embed', 'start': 484.887, 'weight': 0, 'content': [{'end': 490.729, 'text': "OK, so now that that's done, when we hit Edit, what happens? Well, it doesn't really do anything.", 'start': 484.887, 'duration': 5.842}, {'end': 493.771, 'text': "We're not going through and checking if the form exists.", 'start': 490.769, 'duration': 3.002}, {'end': 499.553, 'text': "In fact, what is happening is it's taking us back through and then redirecting us back to list.php.", 'start': 494.291, 'duration': 5.262}, {'end': 502.894, 'text': 'So we need to handle this over here.', 'start': 500.293, 'duration': 2.601}, {'end': 504.935, 'text': "And we're going to do that at the very top here.", 'start': 503.194, 'duration': 1.741}, {'end': 509.337, 'text': 'So we want to check in the same way that we check when we were adding.', 'start': 505.916, 'duration': 3.421}, {'end': 514.03, 'text': 'if the post superglobal array is not empty.', 'start': 510.808, 'duration': 3.222}, {'end': 520.554, 'text': 'Now we want to pull in the ID, label, title, slug and body that have been submitted again.', 'start': 515.131, 'duration': 5.423}, {'end': 522.294, 'text': 'So we say ID.', 'start': 521.274, 'duration': 1.02}, {'end': 527.258, 'text': 'We assign post ID to that.', 'start': 525.176, 'duration': 2.082}, {'end': 533.141, 'text': 'We can duplicate this down and grab the label.', 'start': 529.779, 'duration': 3.362}, {'end': 537.784, 'text': 'We can grab the title.', 'start': 536.663, 'duration': 1.121}, {'end': 546.452, 'text': 'We can grab the slug here and last but not least the body.', 'start': 541.189, 'duration': 5.263}], 'summary': 'The script checks for form submission and retrieves specific data from the post superglobal array.', 'duration': 61.565, 'max_score': 484.887, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8484887.jpg'}, {'end': 607.426, 'src': 'embed', 'start': 574.998, 'weight': 2, 'content': [{'end': 577.981, 'text': "So we're going to update the table pages.", 'start': 574.998, 'duration': 2.983}, {'end': 587.288, 'text': "We're going to set, and I'm just going to tab in here so it's a little bit more readable, label equal to a label placeholder.", 'start': 579.022, 'duration': 8.266}, {'end': 588.529, 'text': 'We have a comma here.', 'start': 587.569, 'duration': 0.96}, {'end': 590.631, 'text': 'And again, we can duplicate this down.', 'start': 589.07, 'duration': 1.561}, {'end': 594.154, 'text': 'We want to update title to title.', 'start': 591.472, 'duration': 2.682}, {'end': 597.937, 'text': 'We want to update slug to slug.', 'start': 595.055, 'duration': 2.882}, {'end': 607.426, 'text': 'body to a body placeholder and then finally updated, which is our column in our database.', 'start': 599.558, 'duration': 7.868}], 'summary': 'Updating table pages with label, title, slug, body, and updated fields.', 'duration': 32.428, 'max_score': 574.998, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8574998.jpg'}, {'end': 773.17, 'src': 'embed', 'start': 721.047, 'weight': 3, 'content': [{'end': 729.909, 'text': 'We grab our data, we create our prepared statement, we execute with the data that has come from our form, and we redirect the user.', 'start': 721.047, 'duration': 8.862}, {'end': 732.49, 'text': 'And this part updates the record.', 'start': 730.449, 'duration': 2.041}, {'end': 739.354, 'text': "So on this is the first page or the first page, we'll go ahead and update this very slightly.", 'start': 733.79, 'duration': 5.564}, {'end': 741.135, 'text': "So we'll add an exclamation mark.", 'start': 739.374, 'duration': 1.761}, {'end': 744.337, 'text': 'We will change the body.', 'start': 741.815, 'duration': 2.522}, {'end': 745.697, 'text': 'This is the first page.', 'start': 744.397, 'duration': 1.3}, {'end': 748.259, 'text': 'Hope you like it.', 'start': 747.398, 'duration': 0.861}, {'end': 749.68, 'text': "And let's hit edit.", 'start': 748.879, 'duration': 0.801}, {'end': 751.521, 'text': 'And there we go.', 'start': 750.841, 'duration': 0.68}, {'end': 756.104, 'text': 'We can already see that the title has been updated with the exclamation mark.', 'start': 751.561, 'duration': 4.543}, {'end': 762.506, 'text': 'When we click through, we can see that we get the new body and obviously the new title,', 'start': 756.784, 'duration': 5.722}, {'end': 766.247, 'text': 'and you can see that we get last updated and that last updated date.', 'start': 762.506, 'duration': 3.741}, {'end': 773.17, 'text': 'And you can obviously refresh in your database client and you can see that that information has indeed been updated.', 'start': 767.008, 'duration': 6.162}], 'summary': 'Demonstration of updating a record with an exclamation mark and new body, showing last updated date.', 'duration': 52.123, 'max_score': 721.047, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8721047.jpg'}], 'start': 484.887, 'title': 'Handling form submission and updating page data with prepared statements', 'summary': 'Discusses handling form submission and updating page data with prepared statements, covering checking for the existence of the form, pulling specific data, setting label, title, slug, body placeholders, redirecting the user, demonstrating the process through a form submission and database update, and showing an updated page in the cms.', 'chapters': [{'end': 546.452, 'start': 484.887, 'title': 'Handling form submission', 'summary': 'Discusses handling form submission, including checking for the existence of the form and pulling in specific data from the submitted form.', 'duration': 61.565, 'highlights': ['The chapter discusses the process of handling form submission and the need to check if the form exists, highlighting the action of redirecting back to list.php when hitting Edit.', 'It emphasizes the importance of checking if the post superglobal array is not empty and pulling in specific data, such as ID, label, title, slug, and body, from the submitted form.']}, {'end': 787.033, 'start': 548.093, 'title': 'Updating page data with prepared statements', 'summary': 'Covers updating page data using prepared statements, including setting label, title, slug, body placeholders, and redirecting the user, demonstrating the process through a form submission and database update, with the final demonstration showing an updated page in the cms.', 'duration': 238.94, 'highlights': ['The process of updating page data using prepared statements and placeholders is demonstrated, including setting label, title, slug, body placeholders, and redirecting the user. The chapter covers the process of updating page data using prepared statements and placeholders, demonstrating the setting of label, title, slug, body placeholders, and redirecting the user.', 'The form submission process and database update are explained, including creating a prepared statement, executing with form data, and redirecting the user. The form submission process and database update are explained, including creating a prepared statement, executing with form data, and redirecting the user.', 'A demonstration of the updated page in the CMS is provided, showing the modified title, body, and last updated date. A demonstration of the updated page in the CMS is provided, showing the modified title, body, and last updated date.']}], 'duration': 302.146, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ao-fTUiM1U8/pics/ao-fTUiM1U8484887.jpg', 'highlights': ['The chapter discusses the process of handling form submission and the need to check if the form exists, highlighting the action of redirecting back to list.php when hitting Edit.', 'It emphasizes the importance of checking if the post superglobal array is not empty and pulling in specific data, such as ID, label, title, slug, and body, from the submitted form.', 'The process of updating page data using prepared statements and placeholders is demonstrated, including setting label, title, slug, body placeholders, and redirecting the user.', 'The form submission process and database update are explained, including creating a prepared statement, executing with form data, and redirecting the user.', 'A demonstration of the updated page in the CMS is provided, showing the modified title, body, and last updated date.']}], 'highlights': ['The process involves hooking up a link to an edit page, passing in the page ID through the URL, and creating an edit page to modify the data, showcasing the generation of specific URLs and data insertion.', 'The chapter demonstrates the steps to redirect users to the edit page by passing the page ID through the URL and creating an edit.php file to handle the modification of data.', 'Detailing the process of creating an edit page and passing specific IDs through the URL to modify data, showcasing the steps to hook up a link and generate URLs.', "The chapter explains the process of checking if a specific ID exists in the query string and pulling the corresponding record from the database, redirecting users if the ID doesn't exist, and preparing and executing SQL statements with placeholders to retrieve the desired page.", 'The process of preparing a statement to select specific fields from the database, executing the statement with the passed-in ID, and fetching the retrieved page using PDO fetch associative array is detailed, providing insights into the retrieval of database records based on the provided ID.', 'The chapter covers editing page forms by populating existing values, including creating a hidden input field to specify the ID for updating.', 'The process involves copying the add form, changing the action to edit, and adjusting the submit button.', "The form includes a hidden input field with the name 'ID' and the value as the page ID, which is escaped to prevent security risks.", 'The chapter discusses the process of handling form submission and the need to check if the form exists, highlighting the action of redirecting back to list.php when hitting Edit.', 'It emphasizes the importance of checking if the post superglobal array is not empty and pulling in specific data, such as ID, label, title, slug, and body, from the submitted form.', 'The process of updating page data using prepared statements and placeholders is demonstrated, including setting label, title, slug, body placeholders, and redirecting the user.', 'The form submission process and database update are explained, including creating a prepared statement, executing with form data, and redirecting the user.']}