Another Mysql question ^_^<(*T_T*)
this is silly...I cant seem to remember how to check against a mysql query...lol
lets say
profile.php?user=blah
if user blah exists
->show content
else
->show "custom error" message.
but idk why i cant think of any way to do it... i know ive done it before. but i cant remember nore find that damn script. that did it.
YES I AM NOOB. HERE ME WHINE
Re: Another Mysql question ^_^<(*T_T*)
PHP Code:
function user_exists($user)
{
$user = mysql_escape_string($user);
$query = "SELECT DISTINCT null FROM users WHERE user_name='$user'";
if (! ($result = mysql_query($query)) {
echo(mysql_error());
die;
}
if (mysql_fetch_row($result){
return true;
} else {
return false;
}
}
Modify that as you require. The result set returned will return a single row containing a null field if the user exists and an empty result set if the user does not exist.
Re: Another Mysql question ^_^<(*T_T*)
wha....
sorry but i dont understand lol...
from what i gathered... i thought i could do this...lol...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PHP Code:
$query = "SELECT DISTINCT null FROM users WHERE username='Steve'";
if (!$result = mysql_query($query)) {
echo(mysql_error());
die;
}
if (mysql_fetch_row($result))
{
while($row = mysql_fetch_array($result))
{
echo"blah";
echo"$row[username]";
}
} else {
echo"ERROR";
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Re: Another Mysql question ^_^<(*T_T*)
Just modify the query in the function so that the username field and table name match with yours and copy and past the function into your script. Then you can call it as folllows:
PHP Code:
if (user_exists('dave')) {
/* you are a user */
} else {
/* error you are not a user */
}
Re: Another Mysql question ^_^<(*T_T*)