|
-
Nov 13th, 2005, 06:05 AM
#1
Thread Starter
Hyperactive Member
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
Last edited by PlaGuE; Nov 13th, 2005 at 08:52 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 13th, 2005, 07:03 AM
#2
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.
-
Nov 13th, 2005, 08:51 AM
#3
Thread Starter
Hyperactive Member
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";
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Nov 13th, 2005, 08:55 AM
#4
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 */
}
-
Nov 13th, 2005, 09:05 AM
#5
Thread Starter
Hyperactive Member
Re: Another Mysql question ^_^<(*T_T*)
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|