Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4259276
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:45:44+00:00 2026-05-21T05:45:44+00:00

I am trying to enter the date and time into datetime field in MySql.

  • 0

I am trying to enter the date and time into datetime field in MySql. Right now, it is entering the datetime as 0000-00-00 00:00:00. I have 3 tables: article, user, and userarticles.

article: id (int), title (varchar), url (varchar), body (text), date (datetime)
user: id (int) ….
userarticle: uid (int), aid (int) -where uid is user.id and aid is article.id

here is part of my user controller:

function newArticle()
    {
        $this->load->view('newArticleview');
    }

    function insertArticle()
    {
            //insert from form into article table
        $this->db->insert('article', $_POST);

        //get ID of the row just added
        $rowID = $this->db->insert_id();
        $uid = $this->tank_auth->get_user_id();

        $data = array('uid' => $uid, 'aid' => $rowID);

            //insert uid and aid into userarticles table
        $this->db->insert('userarticles', $data);

        redirect('');
    }

my newArticleview

<html>
<head>
    <title>Save Me - Add New Article</title>
</head>
<body>  
<?php
    $date = date("Y-m-d H:i:s");
    echo form_hidden('date', $date);
    echo form_open('user/insertArticle');
?>
<p>Title:<input type="text" name="title"></p>
<p>URL:<input type="text" name="url"></p>
<p><textarea name="body" rows="20"></textarea></p>

<p><input type="submit" value="Submit"></p>

</form>
</body>

</html>

Everything is inserted into the database correctly except for datetime, does anyone know what is wrong?
The hidden form is showing up correctly as <input type="hidden" name="date" value="2011-04-08 21:51:10" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:45:45+00:00Added an answer on May 21, 2026 at 5:45 am

    You are outputting a hidden form field, before the form starts. Not sure if that will break CI but it’s invalid markup. the form_open helper can take a 3rd argument – an array of hidden fields. So something like this can be done instead/addition:

    $hidden=array('item_id'=>$this->uri->segment(3)); 
    echo form_open('admin/do_upload', '', $hidden); ?>
    

    You don’t need to put the date in the view, really, unless you have specific use for it (i.e for use in javascript or something)

    I have something like this in my model for created by/modified by times:

    // $data contains everything from the form, I pass this to my model, and then do:
    
    $data['created'] =  date('Y-m-d H:i:s');
    
    $this->db->insert('my_table', $data);
    

    Where created is my column name.

    If you aren’t using a model, you could put this in your controller instead, but in the interest of MVC it should be in a model really.

    Don’t forget you can always do:

    print_r($this->input->post()) or print_r($_POST) to see what’s really being picked up – using the input library helps to sanities everything for you automatically, it’s not a requirement, obviously, but the functionality is built in to CI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the |date filter and running into some problems. Here
Ok, So I have these two tables - BioUser- UserId,Weight,DateAdded DimDate-Date // It has
My question about My SQL is, I have a table where users enter time
I'm trying to enter a javascript competition where the script has to be <=
Trying to get jQuery to detect enter input, but space and other keys are
I'm trying to get this validation for a date entered, from Jan 01 1901
I have the code below and it works pretty good except if you enter
What i am trying to do is get my user to enter in a
I am trying to do some validation check to the password field a form.
I am using C# and Visual Studio 2005. I have created multiple Texboxes at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.