Php $this->;db->;喜欢不过滤结果

Php $this->;db->;喜欢不过滤结果,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有一个搜索表单内置在我的网站的标题中(我也在使用Bootstrap)。表单的目的是根据输入查询用户 查看 <form class="navbar-form pull-right" method="post" action="updates/search" name="search"> <input type="text" class="input-medium" size="50" placeholder="Search for users" style="padd

我有一个搜索表单内置在我的网站的标题中(我也在使用Bootstrap)。表单的目的是根据输入查询用户

查看

<form class="navbar-form pull-right" method="post" action="updates/search" name="search"> 
    <input type="text" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px">
        <button type="submit" class="btn btn-small" name="sub">Search</button>
    </input>
</form>
控制器

public function index($renderData="")
{ 
    $this->load->model("user_model");
    $this->load->model("updates_model"); 

    $this->_render('pages/search');
}
当我运行搜索查询时,比如说“as;fa;sklfl;kasf”,它仍然会打印数据库(5)中的所有用户名,而不是空白页面。我的get_搜索方法是否出于某种原因找不到$input变量

编辑:我修复了它。我的值在表单中,而不是在输入中

$this->db->like('username',$input); 
$query = $this->db->get('users');
like查询与变量$query的关联在哪里

您告诉您的框架获取所有用户,并将其设置为$query

$query = $this->db->get('users');

您的文本框未指定任何名称

<input type="text" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px" />

添加
echo$this->db->last_query()
以查看正在运行的实际SQL查询。这可能会有帮助。@Rocket Hazmat好的。。所以当我运行它时,它给出了SELECT*FROM(
users
),其中
username
类似“%”。所以我猜这意味着$input变量没有正确传递?如何调用
get\u search
get?您是如何将输入传递给它的?我在操作中调用它,“更新/搜索”。方法是$this->load->model(“user_model”)$这个->用户模型->获取搜索($this->input->post('search');您的
没有名称。尝试将
name=“search”
移动到
“两者”都是默认值,如果不另行指定:)
function get_search($input)
{
    //you might want to add `%` on your like statement just add both/after/before the third paraeter
    $this->db->like('username',$input,'BOTH'); 
    $query = $this->db->get('users');

    //check the query
    print_r($this->db->last_query());
}
<input type="text" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px" />
  <input type="text" name ="username" class="input-medium" size="50" placeholder="Search for users" style="padding-left:10px"/>
$input = $this->input->post('username');
$this->db->like('username',$input); 
$query = $this->db->get('users');