/    Sign up×
Community /Pin to ProfileBookmark

Checking Username

I have the following code and have problem that it gives me
result :

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in…it works if this is alone but when I put into my web site script it shows me this message. Could you help me what can be wrong?

my Code:

//search for name

$un = $_POST[‘username’];
$query = “SELECT username FROM login WHERE username=’$un’ LIMIT 1”;
$result = mysql_query($query);
$num_rows = mysql_num_rows($result); //Check how many rows are in result

if($num_rows > 0) {
echo “This $un is in DataBase”;
}
else {
echo “This $un is not correct”;
}

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYSep 16.2005 — and the query goes ok?

can you echo out mysql_num_rows($result)?
Copy linkTweet thisAlerts:
@aznchong91Sep 16.2005 — I don't know but maybe you have to add the connection to the query:

[B]$result = mysql_query($query,$yourconnectvariable);[/B]
Copy linkTweet thisAlerts:
@NogDogSep 16.2005 — The "supplied argument is not a valid MySQL result resource" message tells you that the query failed to execute; either there was a syntax error in the query or you are not connected to the database. To debug, try changing your mysql_query line to:
[code=php]
$result = mysql_query($query) or die ("SQL error: $query -- " . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@toplisekauthorSep 21.2005 — thank it works,
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...