how to disply mysql table data on same form and also edit update and delete these data on that form in wordpress

Dani AI

Generated

Good pointers from and : they highlight two core needs — a way to pick which row to act on and a way to apply the change. In WordPress the reliable pattern is to build a single page (shortcode or admin page) that lists rows and exposes an inline edit form. Do not open a separate raw DB connection; use WordPress APIs and handle form submissions securely.

Use one of two UX flows: inline edit with AJAX (cleanest UX) or server-side editing where the same page handles the POST and then redisplays the updated table. For the server-side flow, require a nonce, check current_user_can for permissions, sanitize input, use prepared statements or the WP DB wrapper, then redirect back with a status flag to avoid double submits. For AJAX, use wp_ajax / wp_ajax_nopriv endpoints with the same security checks.

A minimal pattern (illustrative only — adapt before use):

add_shortcode('my_table_editor','mte_shortcode');
function mte_shortcode($atts){
  global $wpdb;
  $table = $wpdb->prefix.'mytable';

  if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['mte_nonce'])){
    if (!wp_verify_nonce($_POST['mte_nonce'],'mte_action')) wp_die('Invalid request');
    if (!current_user_can('edit_posts')) wp_die('No permission');

    $id = intval($_POST['id']);
    $name = sanitize_text_field($_POST['name']);
    $wpdb->update($table, array('name'=>$name), array('id'=>$id), array('%s'), array('%d'));

    wp_safe_redirect(remove_query_arg(array('action')));
    exit;
  }

  $rows = $wpdb->get_results("SELECT * FROM {$table} LIMIT 100", OBJECT);
  // output table + edit form (include wp_nonce_field('mte_action','mte_nonce'))
}

Troubleshooting tips: confirm table name includes $wpdb->prefix, enable WP_DEBUG for errors, inspect capability checks if actions silently fail, and verify nonces when edits are rejected. For reference: see the WP DB wrapper and nonces documentation for implementation details: wpdb class and nonces.

Recommended Answers

All 2 Replies

I am a newbie myself, but maybe can I advice you to

1) fist make a connection to your database
2) You can use Update and delete quries.

Are you using PhpMyAdmin?

You can use the $_GET variable to get data on the same page and us it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.