View Single Post
Old 01-03-2013, 02:34 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,500
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Dormilich View Post
easiest and most failsafe method is making the username column either the Primary Key or UNIQUE.
I'm also going with this too

@LearningCoder, while selecting will work it's an extra query to run on the sql server. IF you get too many of those it will grind to a halt.

If you set the column to unique and try to insert an existing user, the sql server won't insert it. You can then test whether or not the user was inserted by using mysql_num_rows() which will tell you how many rows were inserted - of course if there were none due to the username already existing then it will be 0. This doesn't (afaik) run a second query on the server because mysql automatically counts the affected rows and returns it with each query and holds it in memory meaning that you don't need to run another query on the database files to get the number.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
LearningCoder (01-03-2013)