ckportfolio.com - PHP and MySQL: INCLUDE and INSERT

PHP and MySQL: INCLUDE and INSERT

Shared scripts

It's time for us to move onto populating post.php, which will host the form that the user can use to push data into the database.

Before that can take place, however, we should recognize that there is plenty of code above and below the core components of index.php and find a way to modularize it to prevent redundancy. In short, we do not want to write identical code multiple times.

Identify them and bring into the two separate files we created previously: header.php and footer.php. Instead of writing out all the connections to Bootstrap directly in index.php, we can simply call these newly modules using include:

As you can imagine, we can use the same technique for our post.php page. Use the <form> element found in the Exercise Materials archive and style accordingly:

You may have noticed that <form> is referring to a file called upload.php, which we can populate using the Exercise Materials archive:

As the code comments indicate, this script is responsible for pushing whatever that was provided by post.php into the database. Note that the script gathers the provided data, generates another query (which starts with INSERT), and redirects the user back to index.php.

We can now read as well as write using the database.

Screencast Recording

https://www.dropbox.com/scl/fi/fka5wymgf198r463i9s7r/Page-3.mov?rlkey=1bvnthv4m1qhgcyo1878vphq5&dl=0

Fin