Firstly i created a custom table into the wpdb :
global $wpdb;
$table_name = $wpdb->prefix . 'countdown_table';
$sql = '
`id` int(11) NOT NULL AUTO_INCREMENT,
`styleName` varchar(255) NOT NULL,
`css` blob NOT NULL,
`expiration` blob NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
';
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
Then i created a form to send values into the custom table :
<p>Style Name</p>
<form action="" method="POST">
<input type="text" name="style_name">
<input type="submit" name="submit">
</form>
if (isset($_POST['style_name'])) {
$style_name = $_POST['style_name'];
global $wpdb;
$wpdb->insert(
'countdown_table',
array(
'styleName' => $style_name
),
array(
'%s'
)
);
}
And here is the problem to get results from the table :
global $wpdb;
$output = '';
$table_name = $wpdb->prefix . 'countdown_table';
$name = 'styleName';
$results = $wpdb->get_results( $wpdb->prepare('SELECT * FROM '.$table_name ) );
if ( $results ) {
foreach ( $results as $result ){
echo $result[0];
}
The problem is that i cannot display the saved data or do i did something wrong in the code for table creation or inserting data
NOT NULL
wont you have to add the other fields in your insert query?