Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Test wpdb insert plugin
- Description: Test wpdb insert plugin
- Version: 0.1
- Author: Tareq Hasan
- Author URI: http://tareq.wedevs.com
- */
- function test_plugin_menu() {
- add_options_page('Test wpdb insert plugin', 'Test wpdb insert plugin', 9, 'test-wpdb-insert', 'test_wpdb_insert');
- }
- add_action('admin_menu', 'test_plugin_menu');
- function test_wpdb_insert() {
- global $wpdb;
- if( isset( $_POST['test_submit'] ) ) {
- $name = $_POST['test_name'];
- $mail = $_POST['test_mail'];
- $result = $wpdb->insert('test', array('name' => $name, 'email' => $mail), array( '%s', '%s' ) );
- if( $result ) {
- echo '<div class="updated fade" id="message"><p><strong>Inserted.</strong></p></div>';
- } else {
- echo 'something went wrong';
- }
- }
- ?>
- <div class="wrap">
- <h2>Test</h2>
- <form method="post" action="">
- <table class="form-table">
- <tr valign="top">
- <th scope="row">Name</th>
- <td> <input type="text" name="test_name" value="" />
- <span class="description">Enter name</span>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row">Email</th>
- <td>
- <input type="text" name="test_mail" value="" />
- <span class="description">Enter your mail</span>
- </td>
- </tr>
- </table
- <p class="submit">
- <input name="test_submit" type="submit" class="button-primary" value="<?php _e('Add') ?>" />
- </p>
- </form>
- </div>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement