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

    Join Date
    Apr 2012
    Posts
    51
    Rep Power
    3

    My Select query is not working


    Hi everyone

    i am slightly perplexed here; my very simple sql SELECT query is not working.

    the query is suppose to check whether an email address already exist in the system.

    So, query is below.
    PHP Code:
     
    $dbc 
    // this is database connection. 

    $email // this is the  dynamically produced email adddress of the proposed new member. 
        
        
    $q "SELECT user_id FROM  members WHERE email='$email'";
            
    $r mysqli_query ($dbc$q) or trigger_error("Query: $q\n<br />MySQL Error: " mysqli_error($dbc));
            
            if (
    mysqli_num_rows($r) == 0
            
            { 

    //enter new email address.  
                      

    i have tested the above query in Mysql ,against an email address that i know already exists in the system, and Mysql gave me this message;

    MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec )
    Can anyone give me a pointer where i have gone wrong.


    i enclose below a copy of the table


    PHP Code:

    CREATE TABLE members
    (
    user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
    contact_ name VARCHAR (120NOT NULL
    location varchar (120NOT NULL,
    email VARCHAR (70NOT NULL,
    profession varchar (120NOT NULL,
    number int(11NOT NULL
    INDEX user_id (user_id), 

    ); 
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,196
    Rep Power
    4279
    exactly what query did you test in mysql?

    p.s. i'm moving this thread to the php forum because that is likely the source of your error
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,489
    Rep Power
    594
    It is obvious from the message that there were no rows that met the criteria of your query. As r937 asked, what is echo'ed value of '$q'?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    51
    Rep Power
    3
    Originally Posted by r937
    exactly what query did you test in mysql?

    p.s. i'm moving this thread to the php forum because that is likely the source of your error
    hello everyone
    thanks for your responce.

    the query taht i tested in mysql was:
    PHP Code:
    SELECT user_id FROM  members WHERE email='aaa' 
    please note that i placed test data in the column for 'email'.

    it was 'aaa'. So, this mysql query should have returned at least one row for the user_id where the email address was 'aaa'.

    was my select query in correct.

    warm regards

    Andreea
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Open the table in your query browser or phpmyadmin or whatever. Are you POSITIVE that row is there? Are you positive that the field is just 'aaa' and not 'aaa '?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,196
    Rep Power
    4279
    why would you have a test email value of 'aaa' ???

    would it not be something more like 'aaa@something.com'

    your query is fine, by the way
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo