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

in php adding a page that lets you add and delete makes of cars. You will also a

ID: 3748421 • Letter: I

Question

in php adding a page that lets you add and delete makes of cars. You will also add edit buttons to the Parts List table, which will include an Edit Part form.

In the make_list.php file, write the code that creates the make table with all of the make names in the first column and Delete buttons in the second column (see below). It should work similarly to how the index.php file works.

here is the code :

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

// Get all makes
$query = 'SELECT * FROM makes
ORDER BY makeID';
$statement = $db->prepare($query);
$statement->execute();
$makes = $statement->fetchAll();
$statement->closeCursor();
?>
<!DOCTYPE html>
<html>

<!-- the head section -->
<head>
<title>Dooley's Automotive</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>

<!-- the body section -->
<body>
<header><h1>Part Manager</h1></header>
<main>
<h1>Make List</h1>
<table>
<tr>
<th>Name</th>
<th>&nbsp;</th>
</tr>
  
<!-- Add a php block with a foreach loop and you will need an echo statement
       as well see page 151 in the textbook -->
<?php foreach ($make as $makeID ):?>

<td> <?php echo $make['makeID']; ?></td>
<td> <?php echo $make</td>
  
</table>

<h2>Add Make</h2>
  
<!-- Add a php block with a foreach loop and you will need an echo statement
       as well see page 151 in the textbook -->
  
<br>
<p><a href="index.php">List Parts</a></p>

</main>

<footer>
<p>&copy; <?php echo date("Y"); ?> Dooley's Automotive, Inc.</p>
</footer>
</body>
</html>



Part Manager Make List Add Make List Par

Explanation / Answer

<?php

require_once('database.php');

// Get all makes

$query = 'SELECT * FROM makes

ORDER BY makeID';

$statement = $db->prepare($query);

$statement->execute();

$makes = $statement->fetchAll();

$statement->closeCursor();

?>

<!DOCTYPE html>

<html>

<!-- the head section -->

<head>

<title>Dooley's Automotive</title>

<link rel="stylesheet" type="text/css" href="main.css" />

</head>

<!-- the body section -->

<body>

<header><h1>Part Manager</h1></header>

<main>

<h1>Make List</h1>

<table>

<tr>

<th>Name</th>

<th>&nbsp;</th>

</tr>

  

<!-- Add a php block with a foreach loop and you will need an echo statement

as well see page 151 in the textbook -->

<?php foreach ($makes as $make ):?>

<td> <?php echo $make['makeID']; ?></td>

<td> <button type="button" id="<?php echo $make['makeID']; ?>">Delete</button></td>

  

</table>

<h2>Add Make</h2>

  

<!-- Add a php block with a foreach loop and you will need an echo statement

as well see page 151 in the textbook -->

Name <input type="text" name="carId" id="carId">

<button type="button">Add</button>

  

<br>

<p><a href="index.php">List Parts</a></p>

</main>

<footer>

<p>&copy; <?php echo date("Y"); ?> Dooley's Automotive, Inc.</p>

</footer>

<script type="text/javascript">

function delete(id){

<?php

$query = 'DELETE FROM makes where makeID=' ?> +id+"'"+<?php

$statement = $db->prepare($query);

$statement->execute();

?>

window.location.reload(); // reloading the page to see changes

}

function add(){

let carId= document.getElementById("carId").value;

<?php

$statement="INSERT INTO makes (makeID) VALUES('"?>+carId+"'"+<?php );

$statement = $db->prepare($query);

$statement->execute();

?>

window.location.reload(); // reloading the page to see changes

}

</script>

</body>

</html>