RE: [PHP] Validate a form entry against an existing entry.

From: Date: Sun, 18 May 2003 20:31:53 +0000
Subject: RE: [PHP] Validate a form entry against an existing entry.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148120@lists.php.net to get a copy of this message
> i have a test form with 1 form field and the data from the form field is > inserted into a mysql db. > > how do i make sure that no 2 same values can go into the database? I want > to validate it using PHP and not JavaScript or anything like that. One way is to let your database handle it by declaring the column to be UNIQUE. Then you simply cannot put a duplicate entry in. You could also manage this with PHP by first doing a select to see if the data exists. If it does not, then insert it, otherwise reject it. You can run into trouble with this in high traffic situations where two people may submit the same data at the same time unless you put locking around both SQL statements. Hope that helps. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/

« previous php.general (#148120) next »