There appears to be a syntax error on line 4.
string is not quoted
↓ ↓ ↓
$sql = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix.credofy_contact_form. " (
Instead, I would recommend moving your table creation logic to a plugin and having it run off an installation hook.
Below is an example:
<?php
/**
* Plugin Name: WPSE 334694
* Plugin URI: https://wordpress.stackexchange.com/q/334694/13418
* Description: Create database table on activation
* Version: 1.0
* Author: You
* Author URI: https://example.com/
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function wpse_334694_create_table() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = "
CREATE TABLE `{$wpdb->base_prefix}credofy_contact_form` (
id mediumint(12) NOT NULL AUTO_INCREMENT,
your_name VARCHAR(200) NOT NULL,
your_email VARCHAR(200) NOT NULL,
your_phone VARCHAR(200) NOT NULL,
your_hobby VARCHAR(200) NOT NULL,
PRIMARY KEY (id) ) $charset_collate;
";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
register_activation_hook( __FILE__, 'wpse_334694_create_table' );
Simply copy this file into a directory name of your choosing in:
/plugins/{your_plugin_dir_name}/index.php
…then activate the plugin. Upon doing so the function wpse_334694_create_table
will run once during activation and not anytime thereafter, unless you deactivate and reactivate the plugin.
Also modify your $wpdb->insert(...)
call as per the following format:
$wpdb->insert(
'table',
array(
'column1' => 'value1',
'column2' => 123
),
array(
'%s', // format of column 1
'%d' // format of column 2
)
);
For further information concerning $wpdb->insert()
please consult the document here which also provides other useful information on how to interact with your database via $wpdb
global.
I would also recommend moving your insertion logic out into a plugin as well, firing off the back of a hook and adding nonce fields to your form for the purpose of validating the request, however that is a little beyond the scope of this question which primarily is focused on resolving your errors.
Recommended reading: