Results 1 to 5 of 5

Thread: Another Mysql question ^_^<(*T_T*)

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    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.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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 */

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Another Mysql question ^_^<(*T_T*)

    ahh..
    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
  •  



Click Here to Expand Forum to Full Width