EDIT_PRODUCT.PHP php // Get the product data $category_id = $_POST['category_id']; $code = $_POST['code']; $name = $_POST['name']; $price = $_POST['price']; $product_id = $_POST['productID'];

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter5: Working With Excel Tables, Pivottables, And Pivotcharts
Section: Chapter Questions
Problem 3.12CP
icon
Related questions
Question

My update button does not work, when i press edit to update data. i get an unidentified index. Plz help!

 

EDIT_PRODUCT.PHP

 

<?php

// Get the product data

$category_id = $_POST['category_id'];

$code = $_POST['code'];

$name = $_POST['name'];

$price = $_POST['price'];

$product_id = $_POST['productID'];




// Validate inputs

if (empty($code) || empty($name) || empty($price)) {

$error = "Invalid product data. Check all fields are try again.";

include('error.php');

} else {

// If valid, add the product to the database

require_once('database.php');

$query = "UPDATE products

SET categoryID = $category_id,

productCode = $code,

productName = $name,

listPrice = $price

WHERE productID = $product_id";

$db->exec($query);

 

// Display the Product List page

include('index.php');

}

EDIT_PRODUCT_FORM.PHP

 

<?php

 

// get post values

$product_id = $_POST['product_id'];

 

// This is the drop down menu next to 'Category:'

require('database.php');

$query = 'SELECT *

FROM categories

ORDER BY categoryID';

$categories = $db->query($query);

 

$query = "SELECT *

FROM products

WHERE productID = $product_id";

$edit_product = $db->query($query);

$edit_product = $edit_product->fetch();

 

// Define the values

$code = $edit_product['productCode'];

$name = $edit_product['productName'];

$price = $edit_product['listPrice'];

$category_id = $edit_product['categoryID'];

 

?>

<!DOCTYPE html>

<html>

 

<!-- the head section -->

 

<head>

<title>My Guitar Shop</title>

<link rel="stylesheet" href="main.css">

</head>

 

<!-- the body section -->

 

<body>

<header>

<h1>Product Manager</h1>

</header>

 

<main>

<h1>Edit Product</h1>

category id: <?php echo $category_id; ?> <br>




<form action="edit_product.php" method="post" id="edit_product_form">

 

<label>Category:</label>

<select name="category_id">

<?php foreach ($categories as $category) : ?>

<option value="<?php echo $category['categoryID']; ?>">

<?php echo $category['categoryName']; ?>

</option>

<?php endforeach; ?>

</select><br>

 

<label>Code:</label>

<input type="input" name="code" value="<?php echo $code; ?>"><br>

 

<label>Name:</label>

<input type="input" name="name" value="<?php echo $name; ?>"><br>

 

<label>List Price:</label>

<input type="input" name="price" value="<?php echo $price; ?>"> <br>

 

<label>&nbsp;</label>

<input type="submit" value="Update Product"><br>

</form>

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

</main>

 

<footer>

<p>&copy; <?php echo date("Y"); ?> My Guitar Shop, Inc.</p>

</footer>

</body>

 

</html>

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Table
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning