Can we make an application in PHP

Programming a database application with PHP step by step

In the following tutorial we will create a complete database application using PHP step by step. From the creation of the SQL database and tables to the listing, sorting and maintenance of the data, the entire process should be viewed and programmed step by step with the necessary explanations.

In this way, the understanding of the interaction between PHP and database systems is built up and you can later program your database application for your own needs.

In the first example below, we set up a small address management system. The data structure is kept very simple. It is about the understanding and the function and how gradually all the necessary functions are built in.

Have fun recreating and learning about PHP with database access.

Preparation program for address management

First of all we create a database in phpMyAdmin to see how this works and how content can be added via phpMyAdmin and displayed in front of everyone.

We use as database name:

On the left side of phpMyAdmin we can now see the newly created database.

After creating it, we are already in the database - the selected database can be seen at the top next to the server.

We also get the information message "No table was found in the database". Next we put in the "Structure" tab (this is the first tab above).

So we create a table with the name "contacts" and 5 columns:

Here we assign the names of the individual columns and their type and all other necessary settings:

The name of the first field is "id" - we use this to access individual data records later in order to be able to edit them.

To do this, this number must be unique - in other words, "unique". So that we don't have to worry about this "numbering", we leave that to the database system. A consecutive number is automatically assigned to further data records. The first record becomes 1, the second record 2, and so on. If a data record is deleted in the meantime, this number is missing. This will not be reassigned.

This function that the database system automatically takes care of this unique numbering is independent of phpMyAdmin. This will also happen automatically later when we add records via our PHP application.

A_I -> auto increment

Primary -> so that this column is a primary key.

The first and last name is not clear enough, so we need this key.

The first and last name is not clear enough, so we need this key.

Further fields for our address application

We determine the type of the individual fields:

  • first name varchar 100
  • surname varchar 100
  • notes text
  • creates datetime

After saving, we see the created table in the "Structure" tab:

After creating the table "contacts", which now appears in the listing on the left under the listing of the database "address book", we can display the contents of the table. To do this, simply click on the "Show" tab.

We get the response "MySQL returned an empty result (i.e. zero data records)." This is not surprising, because we have not yet had any data records in this table.

Below this information we can see the query that was created by phpMyAdmin:

Create a data record in phpMyAdmin

Now we create a data set via phpMyAdmin. To do this, simply go to the "Insert" tab.

The field for the "id" should not be filled out. The database system does this itself (and usually better!).

A text with an apostrophe is specifically entered in the "comment" field (more on this later)

The creation date can be entered manually in the "created" field - the function is simple, as the current date and time are then entered automatically.

After sending, we see the instruction created by phpMyAdmin to insert a data record below the message that the data record has been created:

We'll create a second data set right away.

To display the content now go to the "Display" tab

In the next step we will establish a connection to the database via PHP and read and insert data. As a first step, we need the structure of the database.

If you find a bug, please let us know (regardless of whether spelling mistakes or errors in content).

With a mouse Mark the faulty point and take over with the following button:

After submitting it comes here feedback! Please do not send twice. Thanks.