Insert data into new table in WordPress plugin

I am working on a plugin and I create new table with plugin installation, table created successfully.

Now I want to add data in this new table. I create a form in “lsp_manage_foo.php” and write insert query in “lsp_manage_process.php”. When I click on submit button I got the error:

Read More
Not Found

The requested URL /lgs_pro/wp-admin/lsp_manage_process.php was not found on this server.
Apache/2.2.15 (CentOS) Server at 192.168.2.2 Port 80

and in address bar the link is like that:

http://192.168.2.2/lgs_pro/wp-admin/lsp_manage_process.php

What is the issue?

Here is my code:

lsp_manage_foo.php:

<form action="lsp_manage_process.php" method="post" name="lsp_add_foo">
    <table width="100%" border="0" cellspacing="4" cellpadding="0">
        <tr>
            <td width="25%">
                  <label>
                       foo Name
                  </label>
            </td>
            <td width="58%">
                 <input type="text" name="lsp_add_foo" id="lsp_add_foo" value="">
            </td>
            <td width="10%" align="right">
                 <input type="submit" name="lsp_save_foo" value="Add Foo">
            </td>
         </tr>
     </table>
</form>

lsp_manage_process.php:

<?php
    global $wpdb;
    $foo_add = $wpdb->prefix."lsp_foo";

    $lsp_foo_name = stripslashes(strip_tags($_POST['lsp_add_foo']));

    $foo_shortcode = str_replace(" ", "_", $lsp_foo_name);
    $foo_shortcode = strtolower($foo_shortcode);

    $foo_data = array(
        'foo_name'       =>  $lsp_foo_name,
        'foo_shortcode'  =>  $foo_shortcode
    );

    $foo_insert = $wpdb->insert($foo_add,$foo_data);

    header("Location: lsp_manage_foo.php");
?>

Related posts

Leave a Reply

1 comment

  1. Ok i find the solution of this issue by myself

    In “lsp_manage_foo.php” file

    <form action="<?php echo plugin_dir_url(__FILE__) ?>lsp_foo/lsp_manage_process.php" method="post" name="lsp_add_foo">
        <table width="100%" border="0" cellspacing="4" cellpadding="0">
            <tr>
                <td width="25%">
                      <label>
                           foo Name
                      </label>
                </td>
                <td width="58%">
                     <input type="text" name="lsp_add_foo" id="lsp_add_foo" value="">
                </td>
                <td width="10%" align="right">
                     <input type="submit" name="lsp_save_foo" value="Add Foo">
                </td>
             </tr>
         </table>
    </form>
    

    And in “lsp_manage_process.php”

    <?php
        require_once( str_replace('//','/',dirname(__FILE__).'/') .'../../../../wp-config.php');
        global $wpdb;
        $foo_add = $wpdb->prefix."lsp_foo";
    
        $lsp_foo_name = stripslashes(strip_tags($_POST['lsp_add_foo']));
    
        $foo_shortcode = str_replace(" ", "_", $lsp_foo_name);
        $foo_shortcode = strtolower($foo_shortcode);
    
        $foo_data = array(
            'foo_name'       =>  $lsp_foo_name,
            'foo_shortcode'  =>  $foo_shortcode
        );
    
        $foo_insert = $wpdb->insert($foo_add,$foo_data);
    
        header("Location: Location: ".site_url()."/wp-admin/admin.php?page=manage_foos");
    ?>
    

    I use this line

    require_once( str_replace('//','/',dirname(__FILE__).'/') .'../../../../wp-config.php');
    

    because my $wpdb not working in this “lsp_manage_process.php”, so i require “config.php” and my $wpdb works perfectly.