Learnit Training
In this chapter we are going to put together everything we have learned before: we will use forms, programming techniques and SQL to communicate with the database.

We continue with the form we already created in chapter 4 (about forms). When processing this response form, which is intended for visitors to a website, we are going to store data in the database. We will also create a system for the administrator of a website to view, modify and discard responses.

7.1. Saving in the database

In

process.php

We checked the entries and displayed them again in the browser. We did not save the data yet. We will do that now.

Task 7.1

Create a folder 7/ in phpcourse/.

Save form.html in phpcourse/7/ (right click, save target as).

Save this program code as process.php in phpcourse/7/.

View the source of phpcourse/7/process.php by opening it in Notepad

Chapter 'Extended Example' of the free course PHP and MySQL. Learnit, also free online webinars with trainer and live online courses with trainer.

Look at what is happening, some things have changed:

There are pieces of text that 

comment

e.g. excel, time management, sql

are added, they always begin with php code. This code is not executed and only serves to make the code more readable for a programmer.The variable $correct has been added. This variable keeps track of errors. As soon as we encounter an error, we set the bolean variable at

false

 (it is not correct).

The bottom piece of code is completely new: //Was alles correct ingevuld? if ($correct) { // Opslaan! // Vul hier de code in om de reactie op te slaan! echo "

Bovenstaande informatie is opgeslagen!
\n"; } else { // Er is ergens een foute waarde ingevoerd, geef de bezoeker de // mogelijkheid om terug te gaan echo "

Er is een foute waarde ingevoerd, ga terug.
\n"; }
At the site of //Was alles correct ingevuld? if ($correct) { // Opslaan! // Vul hier de code in om de reactie op te slaan! echo "

Bovenstaande informatie is opgeslagen!
\n"; } else { // Er is ergens een foute waarde ingevoerd, geef de bezoeker de // mogelijkheid om terug te gaan echo "

Er is een foute waarde ingevoerd, ga terug.
\n"; }
//Fill in the code here to save the reaction!

In this chapter we are going to put together everything we have learned before: we will use forms, programming techniques and SQL to communicate with the database.