Jump to content

Duplicate Entry


I-AM-OBODO

Recommended Posts

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

 

		$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

Link to comment
Share on other sites

Do you mean it allows you to enter a username even if one exists?

 

I'm not sure what you are using for a database layer, but I don't think $query would directly contain the number of rows. I would expect $query to be an object.

 

So with the little code I have to work with I would say you need to do two things. 1) You need to check the actual number of rows returned and 2) you need to check if the rows returned are > (greater than) 0, not 1. As it stands if you have a single username already in the database it will allow another entry. Why? Because 1 is not greater than 1.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.