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

After reviewing the 7 files available in fhcphp.zip, please provide a line by li

ID: 3838824 • Letter: A

Question

After reviewing the 7 files available in fhcphp.zip, please provide a line by line explanation for the following php file in the context of the FHC implementation. Describe how the file is invoked and the input to and output generated by the file.

AddComp.php

  <?php

/* Program: AddComp.php

* Desc:    Adds new record to the database. A confirmation

*          page is sent to the user.

*/

$host = "localhost";

$user = "root";

$password = "shawnee";

$dbname = "FHC";                               

$cxn = mysqli_connect($host,$user,$password,$dbname)    

         or die ("couldn't connect to server");

?>

<html>

<head><title>Add Record</title></head>

<body>

<?php

$query = "INSERT INTO Computer VALUES (NULL, '{$_POST['compName']}', '{$_POST['category']}', '{$_POST['compDescription']}', '{$_POST['price']}', '{$_POST['pix']}')";

$result = mysqli_query($cxn,$query)

      or die ("Couldn't execute query");

$compID = mysqli_insert_id($cxn);    

            

$query = "SELECT * from Computer WHERE compID='$compID'";

$result = mysqli_query($cxn,$query)

       or die ("Couldn't execute query.");

$row = mysqli_fetch_assoc($result);

extract($row);   

                                 

echo "The following computer has been added to the

       Computer Catalog:<br />

       <ul>

        <li>Category: $compType</li>

        <li>Computer Name: $compName</li>

        <li>Computer Description: $compDescription</li>

        <li>Price: $$price</li>

        <li>Picture file: $pix</li> ";

                 

echo "</ul> ";

echo "<a href="InsertComp.php">Add Another Computer</a> ";

?>

<p><a href="FHCHome.php">FHC Home</a></p>

</body></html>

Explanation / Answer

<?php // Indicates the staarting of php script .

/* Program: AddComp.php /* comment line */

* Desc:    Adds new record to the database. A confirmation

*          page is sent to the user.

*/

$host = "localhost"; // Name of the host where server is running .

$user = "root"; // Name of the user .

$password = "shawnee"; //Password of the user .

$dbname = "FHC"; // Name of the database

$cxn = mysqli_connect($host,$user,$password,$dbname) //   Establishing new connection with the server or  

         or die ("couldn't connect to server"); //else display message "could'nt connect to sever"

?> // End of php script .

<html> //Start of Html script

<head><title>Add Record</title></head> //heading of html page with title .

<body> // Start of body

<?php // Start of php script

$query = "INSERT INTO Computer VALUES (NULL, '{$_POST['compName']}', '{$_POST['category']}', '{$_POST['compDescription']}', '{$_POST['price']}', '{$_POST['pix']}')";

/* query for inserting values in computer table by using post method . */

$result = mysqli_query($cxn,$query) // mysql_query function is called ,and stored it in variable result ,

assuming that $cnx is the name of the database.And returns TRUE if operation is successful .

or die ("Couldn't execute query"); // if operation is unsuccessful returns false with message .

$compID = mysqli_insert_id($cxn); //Inserting compID in database by user.

            

$query = "SELECT * from Computer WHERE compID='$compID'"; //Query to select all values from computer table where compID is equal to user given compID.

$result = mysqli_query($cxn,$query)   

       or die ("Couldn't execute query.");

$row = mysqli_fetch_assoc($result); //Fetch a resulting row according to the query .

extract($row); // Import the values of the resulting rows .

                                 

echo "The following computer has been added to the // Display message

       Computer Catalog:<br />

       <ul> // Unordered list

        <li>Category: $compType</li> // items in the list .

        <li>Computer Name: $compName</li>

        <li>Computer Description: $compDescription</li>

        <li>Price: $$price</li>

        <li>Picture file: $pix</li> ";

                 

echo "</ul> "; // End of list

echo "<a href="InsertComp.php">Add Another Computer</a> "; // LInk to some other insertcomp page .

?> // End of php script

<p><a href="FHCHome.php">FHC Home</a></p> // link to home page.

</body></html> //End of html page .