0

我是CodeIgniter的新手。我现在创建了一个在 mysql db 表中插入记录的方法,如果同名的记录已经存在,则使查询停止,所以我写道:

public function set_project()
    {
        // If project name already exists?
        $query = $this->db->query("SELECT pro_id FROM projects WHERE pro_name = '".$this->input->post('pro_name')."'");

        if ( sizeof($query->row_array()) == 0) {

            $data = array(
                'is_featured' => $this->input->post('is_featured'),
                'pro_type' => $this->input->post('pro_type'),
                'pro_name' => $this->input->post('pro_name'),
                'pro_client' => $this->input->post('pro_client'),
                'pro_loc_city' => $this->input->post('pro_loc_city'),
                'pro_loc_state' => $this->input->post('pro_loc_state'),
                'pro_yr_start' => $this->input->post('pro_yr_start'),
                'pro_yr_end' => $this->input->post('pro_yr_end'),
                'pro_loc_cur' => $this->input->post('pro_loc_cur'),
                'pro_size' => $this->input->post('pro_size'),
                'pro_size_cat' => $this->input->post('pro_size_cat'),
                'pro_size_units' => $this->input->post('pro_size_units'),
                'pro_desc' => $this->input->post('pro_desc')
            );

            return $this->db->insert('projects', $data);

        } else {
            return "Already exists";
        }

哪个工作正常,但我可以向谁显示我的视图?

4

2 回答 2

0

好的,我做到了,实际上我必须移动那个签入控制器。

于 2012-05-26T12:49:44.063 回答
0

您正在编写return "Already exists",但要查看输出更改该代码echo '<script>alert("Already exists!")</script>';

于 2013-12-20T10:33:40.420 回答