doujiao1814 2016-04-05 14:47
浏览 43

编译错误无法在代码点火器的写上下文中使用方法返回值

i got this model which inserts data on the database but the problem is, other fields are not required so i did this,

public function insert(){


    if($this->input->post('MNAME') = NULL){
        $mname = "n/a";
    }else{
        $mname = $this->input->post('MNAME');
    }

    if($this->input->post('EXTENSION') = NULL){
        $ext = "n/a";
    }else{
        $ext = $this->input->post('EXTENSION');
    }

    if($this->input->post('EMAIL') = NULL){
        $email = "n/a";
    }else{
        $email = $this->input->post('EMAIL');
    }

    if($this->input->post('CELLNO') = NULL){
        $cell = "n/a";
    }else{
        $cell = $this->input->post('CELLNO');
    }

    if($this->input->post('AGENCY_NO') = NULL){
        $agency = "n/a";
    }else{
        $agency = $this->input->post('AGENCY_NO');
    }

    $input = array(
        'ID_NUM'        => $this->uri->segment(3),
        'FNAME'         => $this->input->post('FNAME'       ),
        'SURNAME'       => $this->input->post('SURNAME'     ),
        'DO_BIRTH'      => $this->input->post('DO_BIRTH'    ),
        'POBIRTH'       => $this->input->post('POBIRTH'     ),
        'SEX'           => $this->input->post('SEX'         ),
        'CIVILSTAT'     => $this->input->post('CIVILSTAT'   ),
        'ID_NAT'        => $this->input->post('ID_NAT'      ),
        'HEIGHT'        => $this->input->post('HEIGHT'      ),
        'WEIGHT'        => $this->input->post('WEIGHT'      ),
        'BLOOD_TYPE'    => $this->input->post('BLOOD_TYPE'  ),
        'RES_ADD'       => $this->input->post('RES_ADD'     ),
        'RES_ZIP'       => $this->input->post('RES_ZIP'     ),
        'PERM_ADD'      => $this->input->post('PERM_ADD'    ),
        'PERM_ZIP'      => $this->input->post('PERM_ZIP'    ),
        'MNAME'         => $mname,
        'EXTENSION'     => $ext,
        'EMAIL'         => $email,
        'CELLNO'        => $cell,       
        'AGENCY_NO'     => $agency,
        'DATE_CREATED'  => date("Y-m-d")
        );

    $insert = $this->db->insert($this->table,$input);

    return $insert;
}

but the problem is that i get this error Can't use method return value in write context says that its on line 108. which, the line 108 is the first if of my model. what is my error? and is there any codes which will be shorter?

  • 写回答

1条回答 默认 最新

  • dongluan5740 2016-04-05 14:59
    关注

    You're only stating 1 = in your IF statements, for future note: It should be 2 ='s in a match.

    I restructured this for you so your code is more readable and short.

    // Checking if they're null and appending n/a if they're
    $example = array('MNAME','EXTENSION','EMAIL', 'CELLNO', 'AGENCY_NO');
    $new = array();
    foreach ($example as $_ex)
    {
        $check = $this->input->post($_ex);
        if ($check == null)? array_push($new, 'n/a') : array_push($new, $check);
    }
    

    Then replace with this (keeping in mind index's start at 0 in an array):

    // Inside your DB insert query
    'MNAME'         => $new[0],
    'EXTENSION'     => $new[1],
    'EMAIL'         => $new[2],
    'CELLNO'        => $new[3],       
    'AGENCY_NO'     => $new[4],
    

    I hope this helped.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?