Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:47:13+00:00 2026-06-16T15:47:13+00:00

I am trying to pull in the users table and if the email is

  • 0

I am trying to pull in the users table and if the email is already in the database, i don’t want the user to be able to add another row with the same email. The below code is what I’ve put together so far but it doesn’t seem to work correctly. Does anybody notice what I am doing wrong?

    $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");
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:47:14+00:00Added an answer on June 16, 2026 at 3:47 pm

    No need for the loop. Just check if the email is being used:

    $query = $this->db->get_where('users', array('email' => $email));
    if ($query->num_rows() > 0) {
      // Show error message as email already exists in the database
    } else {
      // Insert new user
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm trying to pull all photos of a specific user's account via the
I am trying to git pull some repository via root user from any directory.
I'm trying to pull data from the YouTube API into a local MySQL table.
I am trying to pull a specific set of records from a table called
I am trying to pull out the information about each user group, while counting
I am trying to pull 2 different sets of data off of 1 table.
I'm trying to match users with a certain description in one table to a
Basically I'm trying to pull a random poll question that a user has not
I can't seem to pull ordered data from the database. I'm trying to list
I want to pull data from table Province_Notifiers and also fetch all corresponding items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.