October 10th, 2012, 11:14 AM
My Select query is not working
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.
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;
$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.
Can anyone give me a pointer where i have gone wrong.
i enclose below a copy of the table
CREATE TABLE members(
user_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
contact_ name VARCHAR (120) NOT NULL,
location varchar (120) NOT NULL,
email VARCHAR (70) NOT NULL,
profession varchar (120) NOT NULL,
number int(11) NOT NULL,
INDEX user_id (user_id),
October 10th, 2012, 12:16 PM
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
October 10th, 2012, 12:36 PM
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.
October 10th, 2012, 02:36 PM
Originally Posted by r937
thanks for your responce.
the query taht i tested in mysql was:
please note that i placed test data in the column for 'email'.
SELECT user_id FROM members WHERE email='aaa'
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.
October 10th, 2012, 03:02 PM
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.
October 10th, 2012, 03:24 PM
why would you have a test email value of 'aaa' ???
would it not be something more like 'email@example.com'
your query is fine, by the way