How can I check if username already exists in database or not.
shenbagam
0
Newbie Poster
Recommended Answers
Jump to PostJust select the record from your DB. If no records found then it doesn't exist. Your checkh will be something like
$resource = mysql_query (select * from ... where username like '$username'); $num_rows = mysql_num_rows ($resource) if ($num_rows == 0) { // user record doesn't exist } …
Jump to PostDont use the like in the select query. Use the following example for better understanding.
This will work if username is unique in your database
$resource = mysql_query("select * from tablename where username= '$username'"); $result = mysql_fetch_array($resource); if ($result) { if($result["username"] == $username && $result["password"] == …
All 8 Replies
chrishea
182
Nearly a Posting Virtuoso
purushothamj
0
Newbie Poster
R0bb0b
344
Posting Shark
Dragonbaki
4
Junior Poster
Borzoi
24
Posting Whiz
diafol
shenbagam
0
Newbie Poster
joehms22
18
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.