English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,

I need a query that finds out if an entered username exists in the database

So if $username in users table = $entered_username

echo "it exists"

else echo "it doesnt exist"

whats the correct syntax

ive been trying but i cant figure it out

Thanks?

2007-08-21 10:53:37 · 4 answers · asked by jeff lemon 1 in Computers & Internet Programming & Design

4 answers

$query = "SELECT user_id FROM users WHERE username='$username';";
if($result = mysql_query($query)){
if($row = mysql_fetch_array($result)){
$userId = $row['user_id'];
}
}

if($userId > 0){
echo "it exists";
}
else{
echo "it doesn't exist";
}

2007-08-21 11:08:00 · answer #1 · answered by Big D 4 · 1 0

if ($username == $entered_username)
{
echo "it exists";
} else {
echo "it doesn't exist";
}

Is that what you are asking? Or do you want syntax to retrieve the username from the database?

2007-08-21 11:02:22 · answer #2 · answered by Anonymous · 0 0

Your 151st question on how to program...
You are abusing this service, getting aswers from decent programmers to cover for your total incompetence.
Learn PhP through www.php.net.

2007-08-24 22:29:52 · answer #3 · answered by just "JR" 7 · 0 0

It would be something like

SELECT user_name FROM users WHERE
username = $_GET['username'];

2007-08-21 11:08:23 · answer #4 · answered by Ron Guilmet 2 · 0 2

fedest.com, questions and answers