Save sqlcreatedb.php as sqlcreatetable.php.

Which database to use

If you were unable to create the database on the last page of this tutorial read this warning.  Otherwise go on to the next heading.

On all the next few pages you will be told to select a database to use and it will tell you to use ywstutorial which you just created.  If you don't have that database replace it's name with one you do have.  Your database server administrator/Web host should give you that information.  If not display the list of databases as you just learned to do at the bottom of the last page and use one of those (probably the only one there apart from information_schema).

Selecting the database

If you want to add a table you need to first tell the server which database to use.  Add this line between the two existing lines in sqlcreatetable.php:

mysqli_select_db($dbconnection, "ywstutorial");

Remember to change the database name if you are not able to use ywstutorial.

In the line which starts mysqli_query replace the query (the bit inside the quotes) with this similar code:

CREATE TABLE first (personalName varchar(255));

Save and try and you should see nothing (if you get a message that means you did it wrong so fix the problem). 

This query should have created a table called first.  It has also created a field in that table called personalName.  That field is of the data type varchar (used for text) and has a maximum length of 255 characters.  We can check that it worked next.

Displaying tables

Open sqlshowdbs.php and save it as sqlshowtables.php.  If this has become a little confusing don't panic as things will get easier later.

Copy the mysqli_select_db line from sqlcreatetable.php and paste it after the first line in sqlshowtables.php. 

In the query line (which is now the third line) change the query to show tables instead of databases.  You only need to change one word and should be able to guess which one.  Save and try to see if the new table is now there.  You should see this:

    [0] => first
    [Tables_in_ywstutorial] => first

Creating a table with more than one field

When you create most tables you will want to have more than one field.  Save sqlcreatetable.php as sqlcreatetable2.php and replace the mysqli_query line with this one:

mysqli_query($dbconnection, "CREATE TABLE second (productName varchar(255), quantity int, notes varchar(255));");

Save and run and you should have a new table with three fields in it.  If you get an error fix your mistake.  Use sqlshowtables.php to double-check that both tables now exist on the database.