Save sqlinsertwithcode.php as sqlinsertwithformprocess.php.  Open forms.html and save it as sqlinsertwithform.html (if you do not have that you will need to create a form which can submit two text fields).  That page has two fields but they are the wrong ones so:

The form should now ask the user for two names and then send that data to your processing page using POST.  You cannot test this until you have changed the processing page.

On the processing page (sqlinsertwithformprocess.php) you need to change some things which might take a while to understand but are basically:

  1. take the data from the form
  2. put it into the database

More precisely this is what you should now do to sqlinsertwithformprocess.php:

  1. $_POST contains two pieces of data from the form:
    • put each one into a variable ($personalName and $familyName) in the same sort of way you did in phpformprocess.php
  2. you already have a query but that currently inserts some text - we want to insert the values in the variables you just created:
    • in the SQL query line delete Fred and Bloggs from the query but leave the single quotes that were around them (see note 1 below)
    • in their place put the $personalName and $familyName variables (note 2 below)

Save both pages and try entering some names into the form and submitting.  If you get a blank page it probably worked.  You will check that next.  This combination of form and processing is the foundation of almost all data entry on the Web.  Think of any time you have typed something into a Web page and this was probably happening behind the scenes.


  1. In both JavaScript and PHP you have been told you do not need to put quotes around variables but here you seem to be.  The reason is that the variables are part of the PHP code but the quotes are from the SQL query not from PHP.  When PHP executes the line of code it will first replace the variables with the values in them.  Then it will send that changed text to the SQL server and so the values need to be in quotes (and SQL uses single quotes).
  2. You will probably now be getting a bit confused because we have at least five pairs of things using the same names.  Each one is different so you could use different names but each one is involved with the same item of data so it makes sense to use the same name.  Look at your code and make sure you know that:
    1. in the form each field has a matching id and a name (they do not need to match it is just easier that way)
    2. the labels have a for attribute which must match the id of the form field so that the label is attached to the correct field
    3. in the processing page the global variable $_POST has two indexes which were created by the name of each field in the form ($_POST["personalName"] and $_POST["familyName"])
    4. you then put the data from $_POST into two variables using the same names (again no need to use the same but it makes it easier to follow)
    5. in the query there are two database fields which have the same name as the variables containing the data which needs to go into them
    6. there is a reason Web developers are often well paid!