Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PHP web question Ia. Configure to use the new table Modify tma02_admin.php to use the new table. Only a single line of code should be

PHP web question

Ia. Configure to use the new table

Modify tma02_admin.php to use the new table.

Only a single line of code should be changed.

In your solution document, provide your code.

You should perform some tests to be sure that your code is using the new table before moving on, but you do not need to provide evidence of those tests.

Ib. Store booking reference in the database

Modify tma02_save-row.php to add the data from the booking reference field to the database.

Look carefully at how the other data elements are added to the database and reflect that for the booking reference field.

Note carefully that tma02_save-row.php handles two distinct situations; one when the record has been edited and the other when the record is new. Here we are only considering a new record and you need only update that part, leaving the other unchanged.

Add the following two entries:

Table 1: Data to add to database
First name Last name Email Booking Reference
Zinolla Zanda z.zanda@zinc.ac.uk ABC-87654
Zeua Avrenim zeua.avrenim@zmail.ac.uk ACD-54321

If you have created any other records when testing, they should be removed prior to adding the two entries above. The quickest way to clear the test data is to drop and recreate the table using table-manager.php.

Table 2: Database table display
firstname lastname email
Zinolla Zanda z.zanda@zinc.ac.uk
Zeua Avrenim zeua.avrenim@zmail.ac.uk

Table 2 shows the data table which should now be displayed. Notice that the new booking reference column is not currently shown.

In your solution document, provide your code and a screenshot of the web page showing the new table containing entries with the fields completed. You can use the Show/Hide: Data from database table to produce the screenshot if required.

Source code admin.php :

// Allow debugging error_reporting(E_ALL); ini_set('display_errors', 1);

// Define a constant to permit each file we "require" to execute // For security, required PHP files should "die" if SAFE_TO_RUN is not defined define('SAFE_TO_RUN', true);

" $app_title = 'TT284 Block 2 - CRUD App (TMA02)'; $css_file = "tma02_admin.css"; // name of CSS file to load $js_file = "tma02_admin.js"; // name of JavaScript file to load

// Setup flags and other variables used in the application $url = $_SERVER["PHP_SELF"]; // URL of this page for forms to POST to $columns = []; // list of names of columns in database table $task = ''; // task to carry out in response to form submission $id = ''; // ID of row in table being viewed/edited (if any) // Search criteria used by search form and data table $search = ''; // value to search for $sort = 'id'; // column to sort by $order = 'ASC'; // order to sort by // Data shown on data entry form $data = []; // key/value data from form submission or row in database table $valid = true; // whether data in $data is known to be valid $feedback = []; // key/value feedback about invalid data

// Define _e and _x functions require 'helpers.php'; // Output head of page require 'tma02_head.php'; ?>

Executing: connect.php and credentials.php

Connected to database:

In a real application, we should also authenticate the user before we authorise viewing or changing data!

// Read $task and $id (if any) from submitted form data if (!empty($data['task'])) { $task = $data['task']; } if (!empty($data['id'])) { $id = $data['id']; } ?>

 $task ==  and $id ==  

// Task is to start editing a row... if ($task == 'edit') { // So read the row from the database table into $data // This data will be presented by the data form require "tma02_read-row.php"; }

// Task is to save submitted form data to a row in the database table... if ($task == 'save') { // So validate the form data require "tma02_validate.php"; if ($valid) { // And save the row (this will clear $data and $id) require "tma02_save-row.php"; // Row has been saved so reset task/data/id // so that the data table is shown again and the data form is empty $task = ''; $data = []; $id = ''; } }

// Task is to delete a row from the database table... if ($task == 'delete') { // So delete the row (this will clear $id) require "tma02_delete-row.php"; // Row has been saved so reset task/data/id // so that the data table is shown again and the data form is empty $task = ''; $id = ''; }

// Now we have carried out tasks, output HTML forms and tables

// Output a form to search or sort with // This also processes search criteria used by the data table require "tma02_search-form.php";

// Output a table of rows in the database table matching search criteria (if any) require "tma02_data-table.php";

// Output a form to enter or edit data (using $data and $id) require "tma02_data-form.php"; ?>

Task completed!

Source code tma02_save-row.php:

// Allow debugging error_reporting(E_ALL); ini_set('display_errors', 1);

// Define a constant to permit each file we "require" to execute // For security, required PHP files should "die" if SAFE_TO_RUN is not defined define('SAFE_TO_RUN', true);

" $app_title = 'TT284 Block 2 - CRUD App (TMA02)'; $css_file = "tma02_admin.css"; // name of CSS file to load $js_file = "tma02_admin.js"; // name of JavaScript file to load

// Setup flags and other variables used in the application $url = $_SERVER["PHP_SELF"]; // URL of this page for forms to POST to $columns = []; // list of names of columns in database table $task = ''; // task to carry out in response to form submission $id = ''; // ID of row in table being viewed/edited (if any) // Search criteria used by search form and data table $search = ''; // value to search for $sort = 'id'; // column to sort by $order = 'ASC'; // order to sort by // Data shown on data entry form $data = []; // key/value data from form submission or row in database table $valid = true; // whether data in $data is known to be valid $feedback = []; // key/value feedback about invalid data

// Define _e and _x functions require 'helpers.php'; // Output head of page require 'tma02_head.php'; ?>

Executing: connect.php and credentials.php

Connected to database:

In a real application, we should also authenticate the user before we authorise viewing or changing data!

// Read $task and $id (if any) from submitted form data if (!empty($data['task'])) { $task = $data['task']; } if (!empty($data['id'])) { $id = $data['id']; } ?>

 $task ==  and $id ==  

// Task is to start editing a row... if ($task == 'edit') { // So read the row from the database table into $data // This data will be presented by the data form require "tma02_read-row.php"; }

// Task is to save submitted form data to a row in the database table... if ($task == 'save') { // So validate the form data require "tma02_validate.php"; if ($valid) { // And save the row (this will clear $data and $id) require "tma02_save-row.php"; // Row has been saved so reset task/data/id // so that the data table is shown again and the data form is empty $task = ''; $data = []; $id = ''; } }

// Task is to delete a row from the database table... if ($task == 'delete') { // So delete the row (this will clear $id) require "tma02_delete-row.php"; // Row has been saved so reset task/data/id // so that the data table is shown again and the data form is empty $task = ''; $id = ''; }

// Now we have carried out tasks, output HTML forms and tables

// Output a form to search or sort with // This also processes search criteria used by the data table require "tma02_search-form.php";

// Output a table of rows in the database table matching search criteria (if any) require "tma02_data-table.php";

// Output a form to enter or edit data (using $data and $id) require "tma02_data-form.php"; ?>

Task completed!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions