Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 Codeigniter如何向用户添加年份';s的注册日期_Php_Mysql_Forms_Codeigniter_Date - Fatal编程技术网

Php Codeigniter如何向用户添加年份';s的注册日期

Php Codeigniter如何向用户添加年份';s的注册日期,php,mysql,forms,codeigniter,date,Php,Mysql,Forms,Codeigniter,Date,我有一个用户注册表单,我需要插入一个函数来创建客户端的到期日期。1年或2年取决于下拉选择 如何在创建用户时将年份值添加到注册日期 这是一个新用户的控制器 function new_member() { $data = array( 'Last_Name' => $this->input->post('Last_Name'), 'First_Name' => $this->input->post('First_Na

我有一个用户注册表单,我需要插入一个函数来创建客户端的到期日期。1年或2年取决于下拉选择

如何在创建用户时将年份值添加到注册日期

这是一个新用户的控制器

    function new_member()
{
    $data = array(
        'Last_Name' => $this->input->post('Last_Name'),
        'First_Name' => $this->input->post('First_Name'),
        'Salutation' => $this->input->post('Salutation'),
        'Address' => $this->input->post('Address'),
        'City' => $this->input->post('City'),
        'Province' => $this->input->post('Province'),
        'Postal' => $this->input->post('Postal'),
        'Email' => $this->input->post('Email'),
        'Dial_Up' => $this->input->post('Dial_Up'),
        'Phone_1' => $this->input->post('Phone_1'),
        'Phone_2' => $this->input->post('Phone_2'),
        'Language' => $this->input->post('Language'),
        'Membership_Cat' => $this->input->post('Membership_Cat'),
        'Special_Member_Cat' => $this->input->post('Special_Member_Cat'),
        'Membership_Status' => $this->input->post('Membership_Status'),
        'Date_DNR' => $this->input->post('Date_DNR'),
        'Gift_Membership' => $this->input->post('Gift_Membership'),
        'Gift_Giver' => $this->input->post('Gift_Giver'),
        'Membership_Length' => $this->input->post('Membership_Length'),
        'Dues_Paid' => $this->input->post('Dues_Paid'),
        'Donation' => $this->input->post('Donation'),
        'Payment_Method' => $this->input->post('Payment_Method'),
        'Date_Received' => $this->input->post('Date_Received'),
        'Date_Input' => $this->input->post('Date_Input'),
        'Membership_Date' => $this->input->post('Membership_Date'),
        'Renew_Letter_1' => $this->input->post('Renew_Letter_1'),
        'Renew_Letter_2' => $this->input->post('Renew_Letter_2'),
        'Renew_Letter_3' => $this->input->post('Renew_Letter_3'),
        'Date_Letter_Sent' => $this->input->post('Date_Letter_Sent'),
        'Vol_FA' => $this->input->post('Vol_FA'),
        'Vol_TEL' => $this->input->post('Vol_TEL'),
        'Vol_CD' => $this->input->post('Vol_CD'),
        'Vol_SCBA' => $this->input->post('Vol_SCBA'),
        'Vol_MAIL' => $this->input->post('Vol_MAIL'),
        'Vol_SML' => $this->input->post('Vol_SML'),
        'Vol_BODCOM' => $this->input->post('Vol_BODCOM'),
        'Vol_OTHER' => $this->input->post('Vol_OTHER'),
        'Member_Since' => $this->input->post('Member_Since'),
        'Notes' => $this->input->post('Notes'),
        );

    $this->membership_model->add_record($data);
    $this->load->view('index_view');
}
这是我的模型

    function add_record($data)
{
    $this->db->insert('Membership', $data);
    return;
}
感谢您的帮助

谢谢

看看PHP strotime()函数,例如

$expiry = date('yy-mm-dd', strtotime('+1 year'));

通过设置数据阵列的方式,您可以使用如下选项:

$date_received = $this->input->post('Date_Received');
$date_expiry =   strtotime(date("Y-m-d", strtotime($date_received)). " +1 year";
$date_expiry_array = array('Date_Received'=>$date_expiry);
$data = array_merge($data, $date_expiry_array);
或者,如果您使用这种方法:

$date_received = $this->input->post('date_received');
$data['date_received'] = strtotime(date("Y-m-d", strtotime($date_received)). " +1 year


如果你想测试1年或2年的到期时间,你可以添加一个If语句来测试date_received的值,然后根据该值添加年数。

我采纳了你的建议并研究了strtotime函数。由于我有2年的会员资格,1年和2年,我还需要提出一个变量I函数。刚刚完成测试,在这里

$Membership_Length = $this->input->post('Membership_Length');
        if($Membership_Length == "1")
        {
            $length = "+1 year";
        }
        else
        {
            $length = "+2 years";
        }

    $Expiry_Date1 = $this->input->post('Membership_Date');
    $Expiry_Date = strtotime($length , strtotime($Expiry_Date1));
    $Expiry_Date = date('Y-m-j', $Expiry_Date);
    $date_expiry_array = array('Expiry_Date' => $Expiry_Date);
    $data = array_merge($data, $date_expiry_array);