Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在mysql中插入的当前日期_Php_Codeigniter - Fatal编程技术网

Php 在mysql中插入的当前日期

Php 在mysql中插入的当前日期,php,codeigniter,Php,Codeigniter,在下面的代码中,我放置了控制器和型号,我插入了名字、姓氏、电子邮件地址、用户名、密码和日期。但我无法将我的当前日期插入mysql,请帮助解决此问题 控制器:登录 function create_member() { $this->load->library('form_validation'); // field name, error message, validation rules $this->form_vali

在下面的代码中,我放置了控制器和型号,我插入了名字、姓氏、电子邮件地址、用户名、密码和日期。但我无法将我的当前日期插入mysql,请帮助解决此问题

控制器:登录

function create_member()
    {
        $this->load->library('form_validation');

        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');


        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('signup_form');
        }

        else
        {           
            $this->load->model('membership_model');

            if($query = $this->membership_model->create_member())
            {
                $data['main_content'] = 'signup_successful';
                $this->load->view('includes/template', $data);
            }
            else
            {
                $this->load->view('signup_form');           
            }
        }
模型:成员资格模型

function create_member()
    {

        $new_member_insert_data = array(
            'first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name'),
            'email_address' => $this->input->post('email_address'),         
            'username' => $this->input->post('username'),
            'date' => $this->input->post('date','curdate()'),
            'password' => md5($this->input->post('password'))                       
        );

        $insert = $this->db->insert('membership', $new_member_insert_data);
        if ($this->db->_error_number() == 1062)
                {
                echo"<script>alert('This value already exists');</script>";
                }
                if ($this->db->_error_number() == "")
                {
                $this->session->set_flashdata('create', 'create');
                }

        return $insert;
    }



function curdate() {
    // gets current timestamp
    date_default_timezone_set('Asia/Manila'); // What timezone you want to be the default value for your current date.
    return date('Y-m-d H:i:s');
}
函数创建_成员()
{
$new\u member\u insert\u data=数组(
'first_name'=>this->input->post('first_name'),
'last_name'=>this->input->post('last_name'),
“电子邮件地址”=>this->input->post(“电子邮件地址”),
'username'=>this->input->post('username'),
'date'=>this->input->post('date','curdate()'),
'password'=>md5($this->input->post('password'))
);
$insert=$this->db->insert('membership',$new\u member\u insert\u data);
如果($this->db->\u error\u number()==1062)
{
echo“警报('此值已存在');”;
}
如果($this->db->\u error\u number()==“”)
{
$this->session->set_flashdata('create','create');
}
返回$insert;
}
函数curdate(){
//获取当前时间戳
date_default_timezone_set('Asia/Manila');//要将哪个时区作为当前日期的默认值。
返回日期(“Y-m-d H:i:s”);
}

我认为这个字符串的问题是:

'date' => $this->input->post('date','curdate()')

您的框架(它是框架?)尝试从post中插入一个值。如果该值为空,则插入curdate()。在MySQL中
NOW()
将插入当前日期或日期时间。

首先,在要输入日期的model方法中,加载“date”助手:

或者,如果您在多个方法中使用它,请继续并将其加载到类构造函数中

然后,要插入当前日期:

    'date' => date('Y-m-d H:i:s', now())

那应该会让你上路的

您的语法中有一个错误:

'date' => $this->input->post('date','curdate()')
应该是

'date' => $this->input->post($this->curdate())
或者,为什么不这样做呢

'date' => date('Y-m-d H:i:s')

我不懂PHP,但您是否尝试过
'date'=>curdate()
?似乎更有意义。插入的日期不正确或为空?是的,我尝试过,但不知道syntaxundefined变量curdate()
'date' => date('Y-m-d H:i:s')