Simple Save Test'; global $wpdb; // Test 1: Check if table exists echo '

Test 1: Check Table

'; $table_name = $wpdb->prefix . 'pc_hfap_snippets'; $exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)); if ($table_name === $exists) { echo '

✓ Table exists: ' . $table_name . '

'; } else { echo '

✗ Table NOT found: ' . $table_name . '

'; echo '

Creating table...

'; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, title varchar(255) NOT NULL, location enum('header','footer','body') NOT NULL DEFAULT 'header', code longtext NOT NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id) ) $wpdb->get_charset_collate();"; dbDelta($sql); $exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)); if ($table_name === $exists) { echo '

✓ Table created!

'; } else { echo '

✗ Failed to create table

'; die('Error: ' . $wpdb->last_error); } } // Test 2: Insert directly echo '

Test 2: Direct Insert

'; $result = $wpdb->insert( $table_name, array( 'title' => 'Direct Test ' . date('Y-m-d H:i:s'), 'location' => 'header', 'code' => '' ), array('%s', '%s', '%s') ); if ($result) { $insert_id = $wpdb->insert_id; echo '

✓ Inserted! ID: ' . $insert_id . '

'; // Test 3: Read back echo '

Test 3: Read Back

'; $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table_name WHERE id = %d", $insert_id), ARRAY_A); if ($row) { echo '

✓ Data retrieved:

'; echo ''; // Test 4: Delete echo '

Test 4: Delete

'; $del = $wpdb->delete($table_name, array('id' => $insert_id), array('%d')); if ($del) { echo '

✓ Deleted successfully!

'; } else { echo '

✗ Delete failed

'; echo '

Error: ' . $wpdb->last_error . '

'; } } else { echo '

✗ Could not retrieve inserted data

'; } } else { echo '

✗ Insert failed

'; echo '

Error: ' . $wpdb->last_error . '

'; echo '

Last query: ' . $wpdb->last_query . '

'; } echo '

Done!

'; echo '

Go to Snippets Page

'; echo '

Add New Snippet

';