ユーザー テーブルを取得しようとしていますが、電子メールが既にデータベースにある場合、ユーザーが同じ電子メールで別の行を追加できるようにしたくありません。以下のコードはこれまでにまとめたものですが、正しく動作していないようです。誰かが私が間違っていることに気づきますか?
$email = $this->input->post('email');
$password = $this->input->post('password');
$firstname = $this->input->post('firstname');
$lastname = $this->input->post('lastname');
$usersAddress = $this->input->post('usersAddress');
$usersCity = $this->input->post('usersCity');
$usersState = $this->input->post('usersState');
$phoneNumber = $this->input->post('phoneNumber');
$query1 = $this->db->get('users');
foreach($query1->result() as $row) {
if ($row->email == $email) {
echo 'Sorry but this email is already in use. Please go back and use a different email.';
} else {
$data = array('email' => $email,
'password' => $password,
'firstname' => $firstname,
'lastname' => $lastname,
'usersAddress' => $usersAddress,
'usersCity' => $usersCity,
'usersState' => $usersState,
'phoneNumber' => $phoneNumber);
$this->db->insert('users', $data);
$this->session->set_userdata('id', $this->db->insert_id());
$this->session->set_userdata('logged', 'true');
$this->session->set_userdata('firstname', $firstname);
$this->session->set_userdata('lastname', $lastname);
$this->session->set_userdata('email', $email);
mail($email,"KyPlays.org","You have successfully regstered at KyPlays.org");
header("Location: ".base_url()."index.php/routers/startpage?requestedPageType=regPart2");
}
}