Welcome Guest, Not a member yet? Register   Sign In
Duplicate Entry
#1

[eluser]Zed[/eluser]
Hi all,
i keep getting double entry in my db. how do i stop it? guess my method is wrong. part of my code below thanks

Code:
$form_data = array(
             'id' => set_value(''),
       'fname' => set_value('fname'),
             'sname' => set_value('sname'),
             'email' => set_value('email'),
             'password' => set_value('password')
      );
      
  
  $query = $this->db->query('SELECT email FROM reg_users');  
  if ($query >1)
  {
  echo 'Username Already exist';
  }
   else{  
     if ($this->reg_model->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
   {
    redirect('forms/success');   // or whatever logic needs to occur
   }

thanks again
#2

[eluser]toopay[/eluser]
@Zed, you evaluating query object, which will returing TRUE or FALSE, so you will never get to first condition. Try :
Code:
$query = $this->db->query('SELECT email FROM reg_users');  

if ( ! empty($query->result_array())
{
  // Exists
}
else
{  
   // Not exists
}
#3

[eluser]InsiteFX[/eluser]
Code:
if ($query->num_rows() > 1)
#4

[eluser]Samus[/eluser]
You should actually really be checking if it's equal to 1.

Emails are unique to a user, they should only occur once.

Code:
if ($query->num_rows() == 1)
#5

[eluser]Zed[/eluser]
have tried all this, but still no luck. i even tried
Code:
$query = $this->db->query('SELECT email FROM reg_users');
if ($query->num_rows() > 0)
{
echo 'duplicate entry';
}
else{

$this->db->insert('reg_users', $data);
}

what it does here is that it does not parse any data into the database but rather echos duplicate entry even when its not duplicate.

any suggestions?

thanks
#6

[eluser]zoopstud[/eluser]
Your not actually checking for a specific email, you are grabbing them all so will always be more than 1 unless the tables empty, you need a where clause to check for the given email. you could always set email as unique in table, and handle it that way.
#7

[eluser]Zed[/eluser]
[quote author="zoopstud" date="1334095780"]Your not actually checking for a specific email, you are grabbing them all so will always be more than 1 unless the tables empty, you need a where clause to check for the given email. you could always set email as unique in table, and handle it that way.[/quote]

even with the other parameter still the same problem

thanks though
#8

[eluser]RiccardoC[/eluser]
Something like this
Code:
$query = $this->db->query("SELECT email FROM reg_users WHERE email = '" . $data[ 'email' ] . "'");
if ($query->num_rows() > 0)
{
echo 'duplicate entry';
}
else{

$this->db->insert('reg_users', $data);
}
Change email and $data["email"] with the field name in your DB
#9

[eluser]zoopstud[/eluser]
[quote author="Zed" date="1334146380"]
even with the other parameter still the same problem

thanks though[/quote]

What parameter?

Code:
$this->db->select('email');
$this->db->from('reg_users');
$this->db->where('email', $email); //$email = $this->input->post('femail') or what ever your email form input is called.
$query = $this->db->get();

if ($query->num_rows() > 0) {
   echo 'duplicate entry';
} else {
   $this->db->insert('reg_users', $data);
}
#10

[eluser]Zed[/eluser]
[quote author="zoopstud" date="1334147134"][quote author="Zed" date="1334146380"]
even with the other parameter still the same problem

thanks though[/quote]

What parameter?

Code:
$this->db->select('email');
$this->db->from('reg_users');
$this->db->where('email', $email); //$email = $this->input->post('femail') or what ever your email form input is called.
$query = $this->db->get();

if ($query->num_rows() > 0) {
   echo 'duplicate entry';
} else {
   $this->db->insert('reg_users', $data);
}
[/quote]


Still not working. I wonder why?




Theme © iAndrew 2016 - Forum software by © MyBB