plznty Posted May 31, 2009 Share Posted May 31, 2009 It does not let me enable the username column to be unique. So how can I go about checking if the username in the column "username" and if there is no duplicates then it gets created. A example of a solution would be of much help, or a theory based comment. Thank you ! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 31, 2009 Share Posted May 31, 2009 It does not let me enable the username column to be unique. Why not? You should enforce this with a UNIQUE INDEX, not PHP code. Quote Link to comment Share on other sites More sharing options...
plznty Posted May 31, 2009 Author Share Posted May 31, 2009 It doesnt let me make it unique? Quote Link to comment Share on other sites More sharing options...
George Botley Posted May 31, 2009 Share Posted May 31, 2009 Are you using a PHP script to do this? If you insert with PHP you can run a query that elimates this from happening. Let me known if you want a script developed. It can take seconds. Yours, George Quote Link to comment Share on other sites More sharing options...
plznty Posted May 31, 2009 Author Share Posted May 31, 2009 Are you using a PHP script to do this? If you insert with PHP you can run a query that elimates this from happening. Let me known if you want a script developed. It can take seconds. Yours, George If you could it would be appreciated. Quote Link to comment Share on other sites More sharing options...
George Botley Posted May 31, 2009 Share Posted May 31, 2009 Ok I am going to assume you have knowldege of PHP queries and POST variables etc so I am going to use a form as an example if someone is signing up. The form: <form name="register" method="post" action="register.php"> <fieldset> <legend>Choose a Username and Password:</legend> <label>Choose a Username:</label> <input type="text" name="username"> <p> </p> <label>Choose a Password:</label> <input type="password" name="password"> <button type="submit">Register!</button> </fieldset> The Script: <?php //Database Connection Information Here $server = "db server"; $dbuser = "dbuser"; $dbpass = "dbpass"; $database = "db" //Set Variables $username = $_POST["username"]; $password = $_POST["password"]; //Connect to database $con = mysql_connect("$server","$dbuser","$dbpass"); $db = mysql_select_db("$database"); //Run Query $query = "SELECT * FROM tablename WHERE username ='$username'"; $query = mysql_query("$query"); $check_username = mysql_num_rows($query); //Check IF Username Exists if("0" != $check_username) { $error_username = "1"; } //Use Result if("1" == $error_username) { header('Location: http://www.example.com/'); //Insert Error Page URL else { INSERT YOUR INSERT QUERIES IN HERE } ?> I hope that helps you and that you can understand it. Let me know if you need help. EDIT: Do you wish to do this in SQL or using a signup facility as if thats the case my script will not function as that checks for existance before inserting or editing databases with PHP. As otherwise what roopurt18 might work if you set your value to varchar with a high limit compared to the password. Quote Link to comment Share on other sites More sharing options...
anupamsaha Posted May 31, 2009 Share Posted May 31, 2009 It doesnt let me make it unique? Seems that your table already has some data. Please check whether there exists duplicate username already in the table or not. If there is already duplicate username exists, you cannot set UNIQUE for the username column. Same goes for blank values in username column. Remove the duplicate username values and/or blanks from the table or change them to some unique values directly into the table, then it will work. Hope this will help. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 31, 2009 Share Posted May 31, 2009 If you do this any other way than with a UNIQUE INDEX then your application is destined for failure. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.