It’s time to write our first example of inserting data in and deleting it from a MySQL table using PHP.
Save file it to your web development directory using the filename sqltest.php
It first checks for any inputs that may have been made and then either inserts new data into the table classics of the publications database or deletes a row from it, according to the input supplied. Regardless of whether there was input, the program then outputs all rows in the table to the browser. So, let’s see how it works. The first section of new code starts by using the isset function to check whether values for all the fields have been posted to the program. Upon confirmation, each line within the if statement calls the function get_post, which appears at the end of the program. This function has one small but critical job: fetching input from the browser.
For reasons of clarity and brevity, and to explain things as simply as
possible, many of the following examples omit certain very sensible
security precautions that would have made them longer and possibly detract from explaining their function in the clearest manner.
Therefore, it is important that you don’t skip past the section later
in this chapter on preventing your database from being hacked , in which you will learn about additional actions you can take with your code to secure it.