#native_company# #native_desc#

Username Duplicate

By Jonathan Finnecy
on December 14, 2000

Version: 1.1

Type: Sample Code (HOWTO)

Category: File Management

License: GNU General Public License

Description: This simple little snippet will check your table to ensure that duplicate entries of form data will not be entered. This example is for a username check, but obviously can be used for most any form entry information.

// Here is the same code written for PostgreSQL.
// Also, the logic is a little clearer... rather than "if (!$numrows < 1)", 
// you can simply use "if ($numrows)" which gives you the same result but a lot
// clearer to the reader (unless you are checking for numrows of -1 - which 
// pgSQL doesn't return to my knowledge)

// Feel free to add error checking according to your whims, of course.

// $conn is your open database connection.

$result = pg_exec($conn,"SELECT userid FROM users WHERE userid = '$uid'");

if (pg_numrows($result)) {
	echo "That user is already registered in the database.<br>n";