PDA

View Full Version : Goodness me ... How do I do that?


zeroge
01-04-2010, 02:42 PM
Hi. ... First, my apology - I'm not a PHP guru. :o

I have worked out a simple form page that contains about 16 text input fields which, upon giving the insert button a punch, will insert all data straight into my DB. you can view the page (http://www.chinabiz21.com/downloads/dataentry_test.php) here.

Now, everything works just like a beauty but I can't figure out the code I'd need that would ...

A - tell me that this record already exists in the database (checking a view fields like, email, mobile, company name for an existing entry) OR

B - tells me the data can't be submitted, because some wrong input was supplied and hence I should check those data before try to submit again.

(I have my DB set up with foreign key constraints like; e.g. the very last field "Client" allows only for entries such as y, n, r, and d - I have the same for other field such as Country, Visa)

Now that's just breaking my old head ... Could somebody help me out, P L E A S E ?

Thank you very much

Old Pedant
01-04-2010, 07:33 PM
Well, the answer to (b) has to be written by you. *WE* can't tell what all constraints you want to put on the data. For example, maybe you want to insist that the user must enter 2 different phone numbers but you provide him 4 choices of which phone numbers to provide. So you will have to provide that kind of logic.

But for (a) ...

One easy way is to create a set of UNIQUE indexes.

Example:
CREATE UNIQUE INDEX emailIndex ON tablename(email);
CREATE UNIQUE INDEX companyIndex ON tablename(company);
CREATE UNIQUE INDEX mobileIndex ON tablename(mobile);

Or maybe you want to allow multiple people from the same company but don't want any individual to be in the DB more than once. Use a composite key, instead:

CREATE UNIQUE INDEX companyAndNameIndex ON tableName(company,lastName);

Now you could have "IBM, Jones" and "IBM, Henderson".

And so on. Look into indexes. They can save you a lot of hassle.