Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate form field for existing data in DB

Status
Not open for further replies.

SLMHC

MIS
Jul 23, 2004
274
CA
I would like to validate a field in a form im developing to check the data base for a duplicate record.

Ive got fields ID, Name, Team.

I would like the Team field to check for an instance of the team already in the DB.

i.e.
Data in DB
ID Name Team
1 Joe bos
2 Jim nyy

I would like the script to check the Team field and if the record(team name) already exists out put an error.

Should i just set the Team field in the DB to be unique and forget coding this function?

-Dave
 
What I would do is set the Team field in the database to unique, then just call the mysql_query() function. After the call to the function, test for a mysql error number (using mysql_errno()) of 1022. This is the duplicate entry error. If this number is what is returned, you can display a message, otherwise, continue on.

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top