<tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_price">Product Price</label> </td> <td> <input name="wpfeatured_product_price" id="wpfeatured_product_price" type="text" value="" class="regular-text" /> </td> </tr> <tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_category">Category</label> </td> <td> <select name="wpfeatured_product_category" id="wpfeatured_product_category"> <?php wpfeatured_product_cta_get_categories(); ?> </select> </td> </tr> </table> <p> <input class="button-primary" type="submit" name="wpfeatured_product_submit" value="Add Product" /> </p> </form> </div> <!-- .inside --> </div> <!-- .postbox --> </div> <!-- .meta-box-sortables .ui-sortable --> </div> <!-- post-body-content -->
function wpfeatured_product_cta_update() { global $wpdb; $id = $_GET["id"]; if (isset($_POST['wpfeatured_product_form_update'])) { $wpproduct_title = esc_html($_POST['wpfeatured_product_title']); $wpproduct_link = esc_html($_POST['wpfeatured_product_link']); $wpproduct_image = esc_html($_POST['wpfeatured_product_image']); $wpproduct_price = esc_html($_POST['wpfeatured_product_price']); $wpproduct_category = esc_html($_POST['wpfeatured_product_category']); $table_name = $wpdb->prefix . 'featured_cta_plugin'; $wpdb->update($table_name, array('title' => $wpproduct_title, 'link' => $wpproduct_link, 'image' => $wpproduct_image, 'price' => $wpproduct_price, 'category' => $wpproduct_category), array('ID' => $id)); } //Selecting the item by ID to display as placeholders in the form... $table_name = $wpdb->prefix . 'featured_cta_plugin'; $selected_product = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE id={$id}", OBJECT); foreach ($selected_product as $s) { $title = $s->title; $link = $s->link; $image = $s->image; $price = $s->price; $category = $s->category; } //And below is the form... ?> <div class="postbox"> <h2><span>Edit <?php echo $title; ?> </span></h2> <div class="inside"> <form name="wpfeatured_product_form_update" method="post" action=""> <input type="hidden" name="wpfeatured_product_form_submitted" value="Y"> <table class="form-table"> <tr> <th class="row">Fields</th> <th>URL</th> </tr> <tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_title">Product Title</label> </td> <td> <input name="wpfeatured_product_title" id="wpfeatured_product_title" type="text" value="<?php echo $title; ?> " class="regular-text" /> </td> </tr> <tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_link">Link to Product Landing Page</label> </td> <td> <input name="wpfeatured_product_link" id="wpfeatured_product_link" type="text" value="<?php echo $link; ?> " class="regular-text" /> </td> </tr> <tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_image">Product Thumbnail Source</label> </td> <td> <input name="wpfeatured_product_image" id="wpfeatured_product_image" type="text" value="<?php echo $image; ?> " class="regular-text" /> </td> </tr> <tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_price">Product Price</label> </td> <td> <input name="wpfeatured_product_price" id="wpfeatured_product_price" type="text" value="<?php echo $price; ?> " class="regular-text" /> </td> </tr> <tr valign="top" class="alternate"> <td scope="row"> <label for="wpfeatured_product_category">Category</label> </td> <td> <select name="wpfeatured_product_category" id="wpfeatured_product_category"> <?php wpfeatured_product_cta_get_categories(); ?> </select> </td> </tr> </table> <p> <input class="button-primary" type="submit" name="wpfeatured_product_form_update" value="Update Product" /> </p> </form> <a href="<?php echo admin_url('admin.php?page=wpfeatured-product-cta'); ?> ">Back to main options page</a> </div> <!-- .inside --> </div> <!-- .postbox --> <?php }