Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 10 The following two tables are part of my STORE database. The first ta

ID: 3842632 • Letter: Q

Question

QUESTION 10

The following two tables are part of my STORE database. The first table is 'products' with a primary key of productId, a foreign key of categoryId, a description of the product, the amount that the store has in inventory, and the price per item.

The second table is 'categories' with a primary key of categoryId and a category type.

The html page printInventory.html (you can see the source by viewing source from 163.238.35.165/~zelikovitz/printInventory.html) has a form with one pull down menu named 'category' that allows a user to choose a category. It also has a button named 'submit'. (THIS BUTTON DOES NOT WORK) The form posts to 'printInventory.php'. Write the script 'printInventory.php' USING PREPARED QUERIES that takes the user's pull down menu input and prints all products in that category. You may assume that a login() function that returns a connection to the database exists, and you can call it.

productId

categoryId

description

inventory

price

1

2

plastic cups plasti

50

1.99

2

2

9 inch plates pactiv

20

5.99

3

2

7 inch plates pactiv

30

4.99

4

2

Bounty paper towels

30

11.99

5

3

Mr. Clean 24 oz

22

3.49

6

3

Fantastic Spray

12

2.89

categoryId

type

1

produce

2

paperware

3

cleaning supplies

4

cereal

productId

categoryId

description

inventory

price

1

2

plastic cups plasti

50

1.99

2

2

9 inch plates pactiv

20

5.99

3

2

7 inch plates pactiv

30

4.99

4

2

Bounty paper towels

30

11.99

5

3

Mr. Clean 24 oz

22

3.49

6

3

Fantastic Spray

12

2.89

Explanation / Answer

printInventory.php

-------------------------------------------------------------------------------

<?php

$searchtype=$_POST["value"];
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);

if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}

$sql="Select categoryId from categories where type= '$searchtype'";

$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$id=$row["id"];

$sql="Select productId,description,inventory,price from products where categoryId= '$id'";

$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0)
{
        echo "<table>";
    echo "<tr>";
echo "<th> productId </th>";
echo "<th>Description</th>";
echo "<th>Inventory</th>";
echo "<th>Price</th>";
   echo "</tr>";
while($row = mysqli_fetch_array($result))
{
   echo "<tr>";
echo "<td>" . $row['productId'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['inventory'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
    echo "</tr>";
}
echo "</table>";

}
else
{
echo "No records matching your query were found.";
}

?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote