2017-07-29 10:06



I'm trying to compare two values in Codeigniter but the result is always false even if the values and type are same. I'm using this piece of code in CodeIgniter. Below code.

$return_name = $this->db->get('feegroup');
$data = $return_name->result();
foreach($data as $d)
    $name = $d->name;
    if(($name) === ($this->input->post("name")))
        $this->session->set_flashdata('error_message',"Sorry cannot create $name fee group, you cannot have two similar fee groups. Either edit or delete $name fee group or change name to create a new fee group.");
    }#EOF IF
}#EOF foreach

I have used trim(), strlen(), is_string() to view the result it shows true everytime but while comparing same data it returns false.

If values from DB comes Sample and If users types sample it returns false but If values from DB comes Sample and If users type Sample it returns True It is not checking the Case.

For example:

1 Parent === Parent = True

2 Parent === parent = False

3 Parent === Sam = False

4 Sam === sam = False

5 heLLO === hello = False

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doxn43207 doxn43207 4年前

    try this

    if(strcasecmp($name,$this->input->post("name")) === 0)
    点赞 评论 复制链接分享
  • doukekui0914 doukekui0914 4年前

    you use strtolower function to convert text into lower case and its compare proper

    if(strtolower($name) === strtolower($this->input->post("name")))
    点赞 评论 复制链接分享