#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    I cannot figure out what I am doing wrong... I am trying to create a "register" page for my site where the user fills in his desired username, real name, password, and his email address... for my example I will be passing $username and $email from a previous form..

    register.php3
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $query1 = "SELECT username FROM tblusers WHERE username='$username'";
    $query2 = "SELECT email FROM tblusers WHERE email='$email'";
    //
    // here's the problem part
    //
    $user_prev_a = MYSQL_QUERY($query1);
    if ($user_prev = MYSQL_FETCH_ARRAY($user_prev_a)) {
    $userexists = 1;
    }
    $email_prev_a = MYSQL_QUERY($query2);

    if ($email_prev = MYSQL_FETCH_ARRAY($email_prev_a)) {
    $emailexists = 1;
    }

    [/code]

    What I'm trying to do is say "Query for the provided username, if it exists in the database, then set $userexists to 1", but what I am getting is the following error :

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    Warning: 0 is not a MySQL result index in /www/yoursite/register.php3 on line 84

    Warning: 0 is not a MySQL result index in /www/yoursite/register.php3 on line 91
    [/code]


    Any help on how to accomplish this would be greatly appreciated.

    Mike
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    Something seems to be the matter with your query, either the table name is wrong or the column name(s) is/are incorrect.

    Use
    else
    print(mysql_error());
    after both IF statements to check the error message.

    Other than that, your code seems to be O.K.
  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    yea,

    The code is correct it seems.

    i think field name must have written wrong.or just check it out whether values are passing correct to the query.

    $result = mysql_query("SELECT * FROM tblusers WHERE username='$username'");

    if (mysql_num_rows($result) == 1)
    {
    $userexists = 1;
    }

    $result1 = mysql_query("SELECT * FROM tblusers WHERE email='$email'");

    if (mysql_num_rows($result1) == 1)
    {
    $emailexists = 1;
    }




    ------------------
    SR -
    shiju.dreamcenter.net
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    3
    Rep Power
    0
    Just a thought.... I don't know if this makes any difference as I always code this way, but I add the final semicolon to the statement. This would make your select clause appear thus :

    ("......where fred=37;");

    ....fred=37[;]"); the semicolon in the Sq brackets is the chap I always add (without the brackets of course).



    ------------------


    GE @ Obsidian Software
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    Thanks for the help peoples... I think what I was really looking for was the MYSQL_NUM_ROWS statement to determine whether or not a record existed...

    Oh, and Shiju, I'm still working on the login script... with this out of the way finally, I'll definitly have it done by this weekend

    Later,
    Mike

Similar Threads

  1. Requesting help on READTEXT statement
    By hdokes in forum MS SQL Development
    Replies: 1
    Last Post: March 19th, 2004, 08:53 AM
  2. Question about the WHERE statement
    By layz d in forum MS SQL Development
    Replies: 5
    Last Post: January 28th, 2004, 11:58 AM
  3. Update database/count statement
    By Signuml99 in forum Database Management
    Replies: 2
    Last Post: November 26th, 2003, 01:07 PM
  4. $Variable Won't Work In "if" Statement
    By Volitics in forum PHP Development
    Replies: 5
    Last Post: September 12th, 2003, 10:33 PM
  5. Figuring out parts of a mySQL statement
    By ChibiGuy in forum PHP Development
    Replies: 2
    Last Post: August 18th, 2003, 10:38 PM

IMN logo majestic logo threadwatch logo seochat tools logo