Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Wordpress插件帮助将输入数据写入数据库_Wordpress - Fatal编程技术网

使用Wordpress插件帮助将输入数据写入数据库

使用Wordpress插件帮助将输入数据写入数据库,wordpress,Wordpress,嗨,我正在制作一个wordpress插件,我需要管理员将数据输入数据库表。当插件激活时,我可以安装db表,但是我不知道如何保存用户输入。我在WP论坛上问过,但他们都死了。。。任何有经验的大师谁可以提供一些指导将不胜感激 <?php /******************************************************************* * INSTALL DB TABLE - ONLY AT RUN TIME

嗨,我正在制作一个wordpress插件,我需要管理员将数据输入数据库表。当插件激活时,我可以安装db表,但是我不知道如何保存用户输入。我在WP论坛上问过,但他们都死了。。。任何有经验的大师谁可以提供一些指导将不胜感激

<?php



/*******************************************************************
*           INSTALL DB TABLE - ONLY AT RUN TIME                    *
*******************************************************************/
function ed_xml_install() {
global $wpdb;

$ed_xml_data = $wpdb->prefix . "ed_xml_data";
if($wpdb->get_var("SHOW TABLES LIKE '$ed_xml_data'") != $ed_xml_data) {

$sql = "CREATE TABLE " . ed_xml_data . " (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  name tinytext NOT NULL,
  address text NOT NULL,
  url VARCHAR(55) NOT NULL,
  phone bigint(11) DEFAULT '0' NOT NULL,
  UNIQUE KEY id (id)
);";

  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  dbDelta($sql);

  $name = "Example Business Name";
  $address = "1234 Example Street";
  $url = "http://www.google.com";
  $phone = "523-3232-323232";

  $insert = "INSERT INTO " . ed_xml_data .
        " (phone, name, address, url) " .
        "VALUES ('" . phone() . "','" . $wpdb->escape($name) . "','" . $wpdb->escape($address) . "', '"  . $wpdb->escape($url) . "')";

  $results = $wpdb->query( $insert );
}
}

//call the install hook
register_activation_hook(__FILE__,'ed_xml_install');

/*******************************************************************
*           CREATE MENU, CREATE MENU CONTENT                       *
*******************************************************************/
if ( is_admin() ){

/* place it under the ED menu */
//TODO $allowed_group = '';

/* Call the html code */
add_action('admin_menu', 'ed_xmlcreator_admin_menu');

function ed_xmlcreator_admin_menu() {
add_options_page('ED XML Creator', 'ED XML Creator', 'administrator', 
'ed_xml_creator',  'ed_xmlcreator_html_page');
}
}

/*******************************************************************
*           CONTENT OF MENU CONTENT                                *
*******************************************************************/


function ed_xmlcreator_html_page() {
<div>
<h2>Editors Deal XML Options</h2>
<p>Fill in the below information which will get passed to the .XML file.</p>
<p>[<a href="" title="view XML file">view XML file</a>]</p>

<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>

<table width="510">
<!-- title -->
<tr valign="top">
<th width="92" scope="row">Deal URL</th>
<td width="406">
<input name="url" type="text" id="url"
value="<?php echo get_option('url'); ?>" />
</td>
</tr>

<!-- description -->
<tr valign="top">
<th width="92" scope="row">Deal Address</th>
<td width="406">
<input name="address" type="text" id="address"
value="<?php echo get_option('address'); ?>" />
</td>
</tr>

<!-- business name -->
<tr valign="top">
<th width="92" scope="row">Business Phone</th>
<td width="406">
<input name="phone" type="text" id="phone"
value="<?php echo get_option('phone'); ?>" />
</td>
</tr>

<!-- address -->
<tr valign="top">
<th width="92" scope="row">Business Name</th>
<td width="406">
<input name="name" type="text" id="name"
value="<?php echo get_option('name'); ?>" />
</td>
</tr>
</table>

<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="hello_world_data" />

<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
</p>

</form>
</div>

?>
前缀。“ed_xml_数据”;
if($wpdb->get_var(“显示像“$ed\u xml\u data”这样的表)!=$ed\u xml\u数据){
$sql=“CREATE TABLE”.ed\u xml\u数据(
id mediumint(9)非空自动增量,
名称tinytext不为空,
地址文本不为空,
url VARCHAR(55)不为空,
电话bigint(11)默认值“0”不为空,
唯一密钥id(id)
);";
require_once(ABSPATH.'wp admin/includes/upgrade.php');
dbDelta($sql);
$name=“示例企业名称”;
$address=“1234示例街”;
$url=”http://www.google.com";
$phone=“523-3232-323232”;
$insert=“插入到“.ed\u xml\u数据中”。
“(电话、姓名、地址、url)”。
“值(“.phone().”、“$wpdb->escape($name)。”、“$wpdb->escape($address)。”、“$wpdb->escape($url)。”)”;
$results=$wpdb->query($insert);
}
}
//调用安装钩子
注册激活钩子(uuu文件,'ed_uxml_安装');
/*******************************************************************
*创建菜单,创建菜单内容*
*******************************************************************/
if(is_admin()){
/*把它放在ED菜单下*/
//TODO$allowed_group='';
/*调用html代码*/
添加操作(“管理菜单”、“ed\u xmlcreator\u管理菜单”);
函数ed_xmlcreator_admin_menu(){
添加选项页面(“ED XML创建者”、“ED XML创建者”、“管理员”,
“ed_xml_creator”、“ed_xmlcreator_html_页面”);
}
}
/*******************************************************************
*菜单内容的内容*
*******************************************************************/
函数ed_xmlcreator_html_page(){
编辑器处理XML选项
填写以下信息,这些信息将传递到.XML文件

[]

交易网址
第一件事首先,你需要在你的管理页面上有一个处理程序来处理已经发布回来的信息。这个处理程序将是实际更新数据库表的代码部分

有一个如何检查提交的帖子数据的示例。下面是一个可以使用的示例:

// mt_options_page() displays the page content for the Test Options submenu
function mt_options_page() {

    // variables for the field and option names 
    $opt_name = 'mt_favorite_food';
    $hidden_field_name = 'mt_submit_hidden';
    $data_field_name = 'mt_favorite_food';

    // Read in existing option value from database
    $opt_val = get_option( $opt_name );

    // See if the user has posted us some information
    // If they did, this hidden field will be set to 'Y'
    if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) {
        // Read their posted value
        $opt_val = $_POST[ $data_field_name ];

        // Save the posted value in the database
        update_option( $opt_name, $opt_val );

        // Put an options updated message on the screen

?>
<div class="updated"><p><strong><?php _e('Options saved.', 'mt_trans_domain' ); ?></strong></p></div>
<?php

    }

    // Now display the options editing screen
//mt\u options\u page()显示测试选项子菜单的页面内容
功能mt_选项_页面(){
//字段和选项名称的变量
$opt_name='mt_最喜欢的食物';
$hidden_field_name='mt_submit_hidden';
$data_field_name='mt_favorite_food';
//从数据库中读入现有选项值
$opt_val=get_option($opt_name);
//查看用户是否向我们发布了一些信息
//如果有,此隐藏字段将设置为“Y”
如果(isset($\u POST[$hidden\u field\u name])&&&$\u POST[$hidden\u field\u name]=='Y'){
//阅读他们的张贴价值
$opt\u val=$\u POST[$data\u field\u name];
//将发布的值保存到数据库中
更新选项($opt\u name,$opt\u val);
//在屏幕上显示选项更新消息
?>


如果($\u POST['Submit']='updateoptions'){//add sql vars to db}不是问题。我希望您能够解决所有问题。