Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1, Create a database table Modify table-manager.php Hint : Examine the file table-manager.php Notice the variable $database_table which must be set to the name of

Q1, Create a database table Modify table-manager.php Hint : Examine the file table-manager.php

Notice the variable $database_table which must be set to the name of your new table required. You will create a table called tt284_oucu. (Where 'oucu' is replaced with your own OUCU).

Your new table will contain all the columns which exist in tt284_guests, with the addition of the new booking reference column. Base your answer closely on the existing SQL statement.

The booking reference field may contain up to 10 characters.

Modify the SQL statement in the $create_sql variable to meet these requirements.

Source code : table-manager.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);

// TODO: Change this value to configure the application $database_table = "tt284_guests"; // name of database table to create/drop

// SQL to create table with appropriate fields // TODO: Change these columns to meet application requirements // There must be a column between each field BUT no comma after the last field $create_sql = "CREATE TABLE $database_table ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50) NOT NULL )";

// SQL to delete table $drop_sql = "DROP TABLE $database_table";

// Setup variables used in the application $url = $_SERVER["PHP_SELF"]; // URL of this page for forms to POST to $tables = []; // list of names of tables in database $columns = []; // list of names of columns in database table (if it exists) $task = ''; // task to carry out in response to form submission

// Define _e and _x functions require 'helpers.php'; ?>

TT284 Table manager

Ask questions about TMA02 (but do not share your work) in the TMA02 forum

zu110279 - Erehwon Guest House

Executing:

This file requires connect.php from Block 2 Part 5 resources to be uploaded to the server!

This file requires credentials.php from Block 2 Part 5 resources to be uploaded to the server!

Executing: connect.php and credentials.php

Connected to database:

Processing submitted form data

// Task is to create the table... if ($task == 'create') { echo '

'; echo 'Creating table "' . _x($database_table) . '"'; echo '
';

// So execute the SQL to create the table if ($database->query($create_sql)) { echo '

'; echo 'Created table "' . _x($database_table) . '"'; echo '
'; } else { echo '
'; echo 'Error creating table: ' . _x($database->error); echo '
'; } }

// Task is to drop the table... if ($task == 'drop') { echo '

'; echo 'Dropping table "' . _x($database_table) . '"'; echo '
';

// So execute the SQL to drop the table if ($database->query($drop_sql)) { echo '

'; echo 'Dropped table "' . _x($database_table) . '"'; echo '
'; } else { echo '
'; echo 'Error dropping table: ' . _x($database->error); echo '
'; } }

// Now present the current state of the database ?>

Reading database tables

query($sql);

if (!$result) { die("Could not execute SQL \"$sql\""); }

// Read each row as an array indexed by numbers while ($row = $result->fetch_row()) { // Put the first item in each row into the tables array $tables[] = $row[0]; } ?>

Reading table columns (if any)

query($sql);

if (!$result) { die("Could not execute SQL \"$sql\""); }

// Read each row as an array indexed by numbers while ($row = $result->fetch_row()) { // Put the first item in each row into the columns array $columns[] = $row[0]; } }

echo '

The following tables currently exist:

';

echo '

    '; // Loop through each value in $tables foreach ($tables as $table) { echo '
  • ' . _x($table) . '
  • '; } echo '
';

if (empty($columns)) { echo '

Table "' . _x($database_table) . '" does NOT exist!

'; } else { echo '

Table "' . _x($database_table) . '" exists with columns:

'; echo '
    '; // Loop through each value in $columns foreach ($columns as $column) { echo '
  • ' . _x($column) . '
  • '; } echo '
'; }

// Finally present a form with buttons to execute the SQL echo '

Create or drop "' . _x($database_table) . '":

'; ?>

If you need to change this SQL, edit then click: ">reload the page.

CREATE DROP
CAREFUL! NO UNDO!

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

Step: 3

blur-text-image

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions