954,591 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Checking for multiple database entries

Hey, I've written a script in PHP that writes data into a MySQL database upon request, but what I'd also like to include is a script that will go in after the request is made, and check to make sure that the same entry does not already exist... and I have no clue where to start. I've never tried to do anything like this before, and am not sure what to do. If I could get some ideas from anyone it would be greatly appreciated. Thanks!

Syneticus
Newbie Poster
19 posts since Jun 2004
Reputation Points: 23
Solved Threads: 0
 

All you have to do is run a select statement looking for the value you just inserted. This goes right after your insert statement.

Here's some pseudo code:
 
1. insert into table(field1) values('value')
2. y = select count(field1) from table where field1 = 'value'
3. if (y == 1)
	  just one exists
   elseif( y > 1)
	  multiple exist


If you need more help let us know.

samaru
a.k.a inscissor
Team Colleague
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You