ZiBaT => Peter Levinsky => Programming => exercise

PHP Pages
including HTML forms

Updated : 2015-08-24


PHP with HTML forms

Mission:

To create and understand PHP - including forms in HTML.

Background:

Html-exercises

W3schools HTML tutorials and PHP tutorials

Exercise

A) Install XAMPP (if you have not done this yet)

Install the stack to run and provide PHP i.e. install XAMPP

This include a webserver (Apache) a datadase (MySQL) and PHP (= AMP)

B) Create your own PHP pages

Start Netbeans, Create a project 'PHP' -> 'PHP Application'

Make a PHP page - see in the PHP tutorials and run your project

THIS WILL FAIL because you run at the IIS express

You need to move your php-file to the xampp special folder (::root-of-your-xampp-instalation::\htdocs\::your-project-name::) - ex: C:\Program Files (x86)\XAMPP\htdocs\MyFirstPHPProject)
Alternative you place your netbeans-project with root in ::XAMPP::\htdocs

Then you starts the XAMPP -> start Apache

NOW your environment works - next step is a little better exercise - i.e. pages with forms

C) Example with form

Make a new PHP-project (possible located in the XAMPP\htdocs folder)

Modify the index.php file to have a form (for HTML-forms see W3C HTML-forms and W3C PHP-forms)

Make a simple page with login-name and phone 'send' this form to welcome.php that prints out the values.

D) Refactor to login

Modify the form to have user-name and password 'send' this to the welcome.php that check the parameters and accept or reject.

What will happen if you change the type to be GET instead of POST? is that wise?

E) Create a profile

Refactor the index.php to hold a button to create a profile -> send to createProfile.php

The creation of the profile should have following fields name, phone, email, password, confirmed password + a create button (perhaps also a cancel-button) send these information to a ConfirmProfile.php.

Extra A) Check and validate your form

See W3C PHP-forms (handling, validation, required, url/e-mail, complete) for improving your form.

Extra B) Add css to your pages

To your PHP pages add some css controled styles.

Extra C) remember login

To remember the login use the session objects to save if user is logged in.

see PHP session