0
我是新手CodeIgniter。我創建了一個在MySQL數據庫表中插入記錄的方法現在使查詢停止,如果具有相同名稱的記錄已經存在,所以我寫道:如果記錄已存在,則顯示消息
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";
}
其工作正常,但誰,我可以顯示消息,我的看法?
是'pro_name'數據庫中唯一的字段嗎? –