1

I just created an theme and make a form that action is options.php but it gives an error of options page is not found. So I decided to make own table inside wp-database by this code using creation of plugin:

register_activation_hook(__FILE__, 'create_javart_theme_settings_table');

function create_javart_theme_settings_table() {

global $wpdb;

$version = get_option('my_plugin_version', '1.0');
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'javart_theme_settings_table';

$sql = "CREATE TABLE $table_name (
    id bigint(20) NOT NULL AUTO_INCREMENT,
    name varchar(200) DEFAULT '' NOT NULL,
    value longtext NOT NULL,
    type varchar(200) NOT NULL,
    PRIMARY KEY  (id)
) $charset_collate;";

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

update_option('my_plugin_version', $version);
}

and this code works fine make a table for me, but when I insert data from the form the page refreshes but nothing is goes to wordpress db.

The form is:

    <form method="post" action="">
        <p>About Us Diagram &nbsp;&nbsp;&nbsp;&nbsp;<input id="title" type="text" name="title" placeholder="Title" /><input type="text" name="content" placeholder="Content" /></p>
            <?php submit_button('Save Settings'); ?>
    </form>

and php code to retrieve this content is

<?php
$titleData = $_POST['title'];
$contentData = $POST['content'];
?>

and reenter to plugin, in plugin to insert the values the code is:

function about_us_form_to_database_exporter() {

global $titleData;
global $contentData;
global $wpdb;

$wpdb->show_errors();
$wpdb->last_query;


$type = 'About Us';
$table_name = $wpdb->prefix . 'javart_theme_settings_table';
$wpdb->insert(
$table_name, array(
'name' => 'Title',
'value' => $titleData,
'type' => 'About Us',
)
);

$wpdb->print_error();
var_dump($wpdb);
}
register_activation_hook(__FILE__, 'about_us_form_to_database_exporter');

then, what is the error that the input not going to wordpress database's table

2

It sounds like it would be simpler to go back and fix your initial try: saving an option to a WP-native table rather than creating your own. Try update_option - it creates an option if it doesn't exist, or updates if it does. This will save you a lot of code and headaches in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.