Checking username availability from database
We will write an example of a registration form that will match a user-entered name against all other names in the database and will notify the user whether that username is available or not.
Getting ready
Create a folder for this recipe inside the Chapter8
directory and name it as Recipe4
. Open phpMyAdmin and create a new table named users
with the following structure and data.
CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO `users` (`id`, `username`, `password`) VALUES (1, 'holmes', 'sherlockholmes'), (2, 'watson', 'johnwatson'), (3, 'sati', 'pranay'), (4, 'mantu', 'ajayjoshi'), (5, 'sahji', 'brijsah'), (6, 'vijay', 'vijayjoshi'), (7, 'brij', 'brijsah'), (8, 'arjun', 'samant'), (9, 'jyotsna', 'sonawane'), (12, 'ravindra', 'pokharia'), (13, 'prakash', 'joshi'), (14, 'sahji2', 'aloklal'), (15, 'basant', 'bhandari')