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
https://forums.phpfreaks.com/topic/260503-duplicate-entry/
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
https://forums.phpfreaks.com/topic/260503-duplicate-entry/#findComment-1335651
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.