title: Update Crud Operation in PHP with form validation and action
body: <p><a href="https://i.stack.imgur.com/FDD7H.jpg" rel="nofollow noreferrer">index.php</a></p>
  
  <p><a href="https://i.stack.imgur.com/TRCqZ.jpg" rel="nofollow noreferrer">edit_product_form.php</a></p>
  
  <p>Data is not being pulled from database when update button is clicked.
  how do you write SQL statement that will pull current data table when update button is clicked.
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      index.php</p>
  
  <pre><code>// edit button
  &lt;td&gt;&lt;form action="edit_product_form.php" method="post"&gt;
                      &lt;input type="hidden" name="product_id"
                             value="&lt;?php echo $product['productID']; ?&gt;"&gt;
                      &lt;input type="hidden" name="category_id"
                             value="&lt;?php echo $product['categoryID']; ?&gt;"&gt;
                      &lt;input type="submit" value="Update"&gt;
                  &lt;/form&gt;&lt;/td&gt;
  
  
  edit_product_form.php
  
  &lt;?php
  require('database.php');
  $query = 'SELECT *
            FROM categories
            ORDER BY categoryID';
  $statement = $db-&gt;prepare($query);
  $statement-&gt;execute();
  $categories = $statement-&gt;fetchAll();
  $statement-&gt;closeCursor();
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;!-- the head section --&gt;
  &lt;head&gt;
      &lt;title&gt;My Guitar Shop&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="main.css"&gt;
  &lt;/head&gt;
  
  &lt;!-- the body section --&gt;
  &lt;body&gt;
      &lt;header&gt;&lt;h1&gt;Update Form&lt;/h1&gt;&lt;/header&gt;
  
      &lt;main&gt;
          &lt;h1&gt;Update&lt;/h1&gt;
          &lt;form action="add_product.php" method="post"
                id="add_product_form"&gt;
  
  
              &lt;label&gt;Code:&lt;/label&gt;
              &lt;input type="text" name="code"&gt;&lt;br&gt;
  
              &lt;label&gt;Name:&lt;/label&gt;
              &lt;input type="text" name="name"&gt;&lt;br&gt;
  
              &lt;label&gt;List Price:&lt;/label&gt;
              &lt;input type="text" name="price"&gt;&lt;br&gt;
  
              &lt;label&gt;&amp;nbsp;&lt;/label&gt;
              &lt;input type="submit" value="Update"&gt;&lt;br&gt;
          &lt;/form&gt;
          &lt;p&gt;&lt;a href="index.php"&gt;View Product List&lt;/a&gt;&lt;/p&gt;
      &lt;/main&gt;
  
      &lt;footer&gt;
          &lt;p&gt;&amp;copy; &lt;?php echo date("Y"); ?&gt; My Guitar Shop, Inc.&lt;/p&gt;
      &lt;/footer&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>// form for edit button actiom</p>
  
  <pre><code>edit_product.php
  
  &lt;?php
  
  // Validate inputs
  if ($product_id == NULL || $product_id == FALSE || $category_id == NULL || 
          $category_id == FALSE || empty($code) || empty($name) || 
          $price == NULL || $price == FALSE ) {
      $error = "Invalid product data. Check all fields and try again.";
      include('error.php');
  } else {
      // If valid, update the product in the database
      require_once('database.php');
      $query = 'UPDATE products
                SET categoryID = :category_id,
                    productCode = :code,
                    productName = :name,
                    listPrice = :price
                 WHERE productID = :product_id';
      $statement = $db-&gt;prepare($query);
      $statement-&gt;bindValue(':category_id', $category_id);
      $statement-&gt;bindValue(':code', $code);
      $statement-&gt;bindValue(':name', $name);
      $statement-&gt;bindValue(':price', $price);
      $statement-&gt;bindValue(':product_id', $product_id);
      $statement-&gt;execute();
      $statement-&gt;closeCursor();
  
      // Display the Product List page
      include('index.php');
  }
  </code></pre>