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.

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

报告相同问题?

悬赏问题

  • ¥20 ue5运行的通道视频都会有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数