Where to start

Hi, i was wondering if anyone could give me some advice. I’m currently in the process of entering data into my database and have one concern.

Duplicate Data!!!

I have thousands of different companies to enter into my database and i haven’t checked the data for duplicates. I can’t do this before entering it so was wondering where i would start in stopping duplicate companies being entered in the database. Is there a way of stopping an INSERT if there is already a certain field in a table that contains the same data.

For example, say i had a company called Andrew and i tried entering another company with the same name. Also, how would i go about having a user friendly error that informs the person entering the data that it is already in the database and takes them back to the form to amend the data being inputted?

Does this make sense? If not i’ll try and make it clearer.

Thanks,
Andrew

What you can do for such things is simply run a select query with the data inputted by they user that you want to check for duplicates on. To avoid case sensitivity I convert all to upper or lower case. And then when you display them convert case back.

Look into these function
strtoupper()
strtolower()
ucfirst()
ucwords()

Next you will want to look into the function of mysql_num_rows()

You can use this function to check for any returned rows. run and if statment on this and if it comes up empty continue on with the Insert statement.

If it comes up full, you will need to pull $_POST[] data and just use something like:

$company_name = $_POST[‘company_address’];

I like to variable most everything out, never know when you will need to come back and use it again.

So with that information you should be able to get pretty good start things and if you run into trouble we are here to help!

Thanks for the reply, i’m sure you’ll hear from me again when i get stuck! :D

Sponsor our Newsletter | Privacy Policy | Terms of Service