Reputation: 41
I trying to save some data from a simple form, into the database. So far all is well, a simple name and the email address, however I want to save the date in which the data was save into the database, but for some reason it's not working, I am getting this error, just as the title suggests:
WordPress database error: [Column 'date' cannot be null]
Here's the code from the form:
if(isset($_POST['submit_ebook_btn'])) {
global $wpdb;
$tablename = $wpdb->prefix.'ebook_users';
$name = $_POST['ebook_name'];
$email = $_POST['ebook_email'];
$insertDb = $wpdb->insert( $tablename, array(
'name' => $name,
'email' => $email,
'date' => the_time('Ymd')
),
array(
'%s',
'%s',
'%s'
));
if($insertDb) { ?>
<div>
<h2>Download the ebook <a href="#">here</a></h2>
</div>
<?php } else {
echo 'Something went wrong! Please try again.';
}
}
Upvotes: 0
Views: 290
Reputation: 11
The current time won't be returned without specifying a null value or else providing a specific time-zone such as $gmt.
function wp_date( $format, $timestamp = null, $timezone = null ) { global $wp_locale;
if ( null === $timestamp ) {
$timestamp = time();
} elseif ( ! is_numeric( $timestamp ) ) {
return false;
}
if ( ! $timezone ) {
Upvotes: 1