top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to create a date stamp and insert it into database in Wordpress?

0 votes
448 views

I want to create a database table with a column corresponding to the time in my wordpress site, so that I can save user actions into this table and know when they did it.

Creating a table:

$sql = "CREATE TABLE IF NOT EXISTS $table_name (
        id INT NOT NULL AUTO_INCREMENT,
        actiontime NOT NULL DATETIME,
        PRIMARY KEY (id)
    ) $charset_collSate;";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    // execute the query
    dbDelta( $sql );

Is this correct?

I would want a time stamp such that I can get the difference on minute/second intervals.

posted Jul 24, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Use this php function to get the current value for a MySQL DATETIME field.

/**
 * Return current date time.
 *
 * @return string ISO date time (Y-m-d H:i:s)
 */
function now()
{
    return date('Y-m-d H:i:s');
}
answer Aug 20, 2017 by Sumana
Similar Questions
0 votes

I am trying to make a custom form and insert into the database but when I click submit nothing happens. Please help me. I did research and changed my code but still same result. I don't know why.

This is the code:

<?php
/*
Template Name: Student
*/
get_header();
?>    
<?php echo "google";?>    
<?php

    if($_POST['Submit'])
        {
         global $wpdb;
         $name=$_POST['aname'];
         $roll=$_POST['aroll'];
         $dept=$_POST['adept'];
              if($wpdb->insert(    
                  'std', array(
                               'name' => $name,
                               'roll' => $roll,
                               'dept' => $dept
                               )
                               ) == false) wp_die('Database insertion failed');
     else 
          echo "<p>Database insertion successful</p>";  
?>
<?php
}
else //else we didnt submit the form, so display the form
{
?>
<form action="" method="post" id="addcourse">
<label> Student Name:<input type="text" 
name="aname" size="30" /></label>
<label> Roll:<input type="text" 
name="aroll" size="30" /></label>
<label> Department:<input type="text" name="adept" size="30" /></label>
<br />
<input type="Submit" id="addcoursesubmit" value="submit" />
</form>
<?php
}

{
}
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
0 votes

I am building a website using Wordpress. However, I have a "About" section on my homepage (index.php) and I would like to make it dynamic and want to show author's information on this section.
I was following a tutorial and they added the following code to show author's information in one of the page:

<?php the_author_meta( 'description' ); ?>

But that doesn't work on my homepage (index.php file). How can I do this? Can anybody help me?

0 votes

I transfer my wordpress website to a new server. I didn't know about appropriate way of taking backup. I just copied all files inside public_html and exported database from phpMyAdmin. Now I am trying to restore files and database.

I copied all files in public_html and made database and imported. Now I am getting HTTP Error 500. Anybody can help me how can I restore these files without losing data.

0 votes

I want to create a shortcode for category title in wordpress to display the category name, and I found this code:

function categories_list_func( $atts ){
 $categories = get_the_category();

     if($categories) {
        foreach($categories as $category) {
            $output .= '<li class="cat-' . $category->cat_ID . '"><a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "Read more posts from : %s" ), $category->name ) ) . '">'.$category->cat_name.'</a></li>';
        }
        $second_output = trim($output);
      }
      $return_string = '<h4>'.__( "Categories :", "my_site").'</h4><div class="overflow"><ul class="post-categories">' . $second_output . '</ul></div>';

 return $return_string;

} // END Categories
add_shortcode( 'categories-list', 'categories_list_func' );

Can anybody help me how I create this shortcode?

0 votes

I just created a custom theme for my wordpress project inside my wp-content/themes/mycustomtheme, I added an index.php and a style.css file to the new theme but when I go to themes in my dashboard the newly created theme is not shown as an option. What else am I missing? Can anybody help me?
This is my style.css

/*
Theme Name: Start WordPress
Theme URI: http://wordpress.org/themes/startwordpress
Author: Me
Author URI: http://wordpress.org/
Description: The Start WordPress theme is my first custom theme.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: bootstrap, black, brown, orange, tan, white, yellow, light, one-
column, two-columns, right-sidebar, flexible-width, custom-header, 
custom-menu, editor-style, featured-images, microformats, post-
formats, rtl-language-support, sticky-post, translation-ready
Text Domain: startwordpress

This theme, like WordPress, is licensed under the GPL .
Use it to make something cool, have fun, and share what you've learned   
with others.
*/
...