Once you have a database with a table in it you can add more fields.  Save sqlcreatetable2.php as sqlcreatefield.php.  Replace the query on line three (just the SQL query inside the quotes) with this query:The three fields in the second table


Save and try.  As ever a blank pages is expected but not all errors are displayed by SQL so we need to check.


To see if a new field was added save sqlshowtables.php as sqlshowfields.php and change the query text (the bit inside the quotes in the third line) to:


You should see a description of the table as an array.  This will include the field names (if you do not have both personalName and age you did something wrong when you created the table and field).  It also shows their data types and some other data which you do not need now.

Change first to second in the DESCRIBE query and save, upload and try to see the other table.  You should see what is in the screen shot to the right.

Deleting fields

Edit sqlcreatefield.php and change the query line to this:

mysqli_query($dbconnection, "ALTER TABLE first ADD familyName varchar(255);");

Use sqlshowfields.php to show the new field in first (you will need to edit one word in the query) to check that it worked and you have three fields now. 

Now save sqlcreatefield.php as sqldeletefield.php and change the query text to:


Save and try.  Use sqlshowfields.php to check there are now just two fields (personalName and familyName).

Data types

SQL has many data types but for now put text into a varchar and whole numbers into int fields.  When you use varchar always choose a length of 255 because it is a clever data type which shrinks to fit the data put into it (in other databases you would be wasting space by setting such a high limit).

You will learn more later.