我尝试在线创建地址簿,但每当我尝试添加新联系人时,它都不会将记录插入数据库。
这是我的代码。
控制器
public function addcontact(){
$this->load->helper('url');
$this->load->model('contacts');
$first_name = $_GET['inputFirstName'];
$last_name = $_GET['inputLastName'];
$contact_number = $_GET['inputContactNumber'];
$address = $_GET['inputAddress'];
$email_address = $_GET['inputEmailAddress'];
$image;
if(isset($_POST['inputPicture'])){
if(getimagesize($_FILES['image']['tmp_name']) == FALSE){
//please select image
}
else{
$image = addslashes($_FILES['image']['tmp_name']);
$name = addslashes($_FILES['image']['name']);
$image = file_get_contents($image);
$image = base64_encode($image);
}
}
$data['first_name'] = $this->filter_input($first_name);
$data['last_name'] = $this->filter_input($last_name);
$data['contact_number'] = $this->filter_input($contact_number);
$data['address'] = $this->filter_input($address);
$data['email_address'] = $this->filter_input($email_address);
$data['picture'] = $image;
$this->contacts->addContacts($first_name, $last_name, $contact_number, $address, $email_address, $image);
$data['title'] = 'Address Book';
$data['contacts_info'] = $this->contacts->getContacts();
$this->load->view('home', $data);
}
模型
function addContacts($first_name, $last_name, $contact_number, $address, $email_address, $image){
$new_contact_data = array(
'first_name' => $first_name,
'last_name' => $last_name,
'contact_number' => $contact_number,
'address' => $address,
'email_address' => $email_address,
'picture' => $image,
);
$this->db->insert('contacts', $new_contact_data);
}
非常感谢任何帮助。
我知道我可以连接到我的数据库,因为我可以在我的主页上加载所有记录。我在向数据库添加记录时遇到了麻烦。