doucu7525 2014-07-16 04:15
浏览 41
已采纳

将数据插入WordPress插件中的新表

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:

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");
?>
  • 写回答

1条回答 默认 最新

  • douhuan5073 2014-07-16 07:02
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error