GIVEN FILES //delete_product.php prepare($query); $statement->bindValue(':product_id', $product_id);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

GIVEN FILES

//delete_product.php

<?php
require_once('database.php');

// Get IDs
$product_id = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT);
$category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT);

// Delete the product from the database
if ($product_id != FALSE && $category_id != FALSE) {
$query = 'DELETE FROM products
WHERE productID = :product_id';
$statement = $db->prepare($query);
$statement->bindValue(':product_id', $product_id);
$success = $statement->execute();
$statement->closeCursor();
}

// Display the Product List page
include('index.php');

 

//delete_category.php

<?php
// Get ID
$category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT);

// Validate inputs
if ($category_id == NULL || $category_id == FALSE) {
$error = "Invalid category ID.";
include('error.php');
} else {
require_once('database.php');

// Add the product to the database
$query = 'DELETE FROM categories
WHERE categoryID = :category_id';
$statement = $db->prepare($query);
$statement->bindValue(':category_id', $category_id);
$statement->execute();
$statement->closeCursor();

// Display the Category List page
include('category_list.php');
}
?>

 

//display_results.php

 

<?php
// get the data from the form
$investment = filter_input(INPUT_POST, 'investment',
FILTER_VALIDATE_FLOAT);
$interest_rate = filter_input(INPUT_POST, 'interest_rate',
FILTER_VALIDATE_FLOAT);
$years = filter_input(INPUT_POST, 'years',
FILTER_VALIDATE_INT);

// set default error message of empty string
$error_message = '';

// validate investment
if ($investment === FALSE ) {
$error_message .= 'Investment must be a valid number.<br>';
} else if ( $investment <= 0 ) {
$error_message .= 'Investment must be greater than zero.<br>';
}

// validate interest rate
if ( $interest_rate === FALSE ) {
$error_message .= 'Interest rate must be a valid number.<br>';
} else if ( $interest_rate <= 0 ) {
$error_message .= 'Interest rate must be greater than zero.<br>';
} else if ( $interest_rate > 15 ) {
$error_message .= 'Interest rate must be less than or equal to 15.<br>';
}

// validate years
if ( $years === FALSE ) {
$error_message .= 'Years must be a valid whole number.<br>';
} else if ( $years <= 0 ) {
$error_message .= 'Years must be greater than zero.<br>';
} else if ( $years > 30 ) {
$error_message .= 'Years must be less than 31.<br>';
}

// if an error message exists, go to the index page
if ($error_message != '') {
include('index.php');
exit();
}

// calculate the future value
$future_value = $investment;
for ($i = 1; $i <= $years; $i++) {
$future_value += $future_value * $interest_rate *.01;
}
// apply currency and percent formatting
$investment_f = '$'.number_format($investment, 2);
$yearly_rate_f = $interest_rate.'%';
$future_value_f = '$'.number_format($future_value, 2);
?>
<!DOCTYPE html>
<html>
<head>
<title>Future Value Calculator</title>
<link rel="stylesheet" href="main.css"/>
</head>
<body>
<main>
<h1>Future Value Calculator</h1>

<label>Investment Amount:</label>
<span><?php echo htmlspecialchars($investment_f); ?></span><br />

<label>Yearly Interest Rate:</label>
<span><?php echo htmlspecialchars($yearly_rate_f); ?></span><br />

<label>Number of Years:</label>
<span><?php echo htmlspecialchars($years); ?></span><br />

<label>Future Value:</label>
<span><?php echo htmlspecialchars($future_value_f); ?></span><br />

<p>This calculation was done on <?php echo date('m/d/Y'); ?>.</p>
</main>
</body>
</html>

Assignment 2-2
•
• Display the results below the form instead of on a separate page.
After each calculation, set the values in the text boxes to empty strings.
Start from the solution for exercise 2-2.
Transcribed Image Text:Assignment 2-2 • • Display the results below the form instead of on a separate page. After each calculation, set the values in the text boxes to empty strings. Start from the solution for exercise 2-2.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education