· 7 years ago · Jan 04, 2019, 02:12 PM
1function test_contact_form() {
2 global $wpdb;
3 $connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
4 mysql_select_db(DB_NAME);
5 if (!$connection){ die('Error: ' . mysql_error());}
6
7 require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
8
9 $db_table_name = $wpdb->prefix . 'contactus_detail'; // table name
10 if( $wpdb->get_var( "SHOW TABLES LIKE '$db_table_name'" ) != $db_table_name ) {
11 if ( ! empty( $wpdb->charset ) )
12 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
13 if ( ! empty( $wpdb->collate ) )
14 $charset_collate .= " COLLATE $wpdb->collate";
15 $sql = "CREATE TABLE " . $db_table_name . " (
16 id int(11) NOT NULL auto_increment,
17 ip varchar(15) NOT NULL,
18 name varchar(60) NOT NULL,
19 emailid varchar(200) NOT NULL,
20 mobileno varchar(10) NOT NULL,
21 message varchar(1000) NOT NULL,
22 PRIMARY KEY (id)
23 ) $charset_collate;";
24
25
26dbDelta( $sql ); // create query
27 }
28 }
29 register_activation_hook(__FILE__, 'test_contact_form');
30
31function test_contact_form()
32{
33 global $wpdb;
34 $db_table_name = $wpdb->prefix . 'contactus_detail'; // table name
35 $charset_collate = $wpdb->get_charset_collate();
36
37 $sql = "CREATE TABLE $db_table_name (
38 id int(11) NOT NULL auto_increment,
39 ip varchar(15) NOT NULL,
40 name varchar(60) NOT NULL,
41 emailid varchar(200) NOT NULL,
42 mobileno varchar(10) NOT NULL,
43 message varchar(1000) NOT NULL,
44 UNIQUE KEY id (id)
45 ) $charset_collate;";
46
47 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
48 dbDelta( $sql );
49 add_option( 'test_db_version', $test_db_version );
50}
51
52register_activation_hook( __FILE__, 'test_contact_form' );
53
54$connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
55 mysql_select_db(DB_NAME);
56 if (!$connection){ die('Error: ' . mysql_error());}
57
58function test_contact_form()
59{
60 global $wpdb;
61 $db_table_name = $wpdb->prefix . 'contactus_detail'; // table name
62 $charset_collate = $wpdb->get_charset_collate();
63
64 //Check to see if the table exists already, if not, then create it
65if($wpdb->get_var( "show tables like '$db_table_name'" ) != $db_table_name )
66 {
67 $sql = "CREATE TABLE $db_table_name (
68 id int(11) NOT NULL auto_increment,
69 ip varchar(15) NOT NULL,
70 name varchar(60) NOT NULL,
71 emailid varchar(200) NOT NULL,
72 mobileno varchar(10) NOT NULL,
73 message varchar(1000) NOT NULL,
74 UNIQUE KEY id (id)
75 ) $charset_collate;";
76
77 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
78 dbDelta( $sql );
79 add_option( 'test_db_version', $test_db_version );
80 }
81}
82
83register_activation_hook( __FILE__, 'test_contact_form' );