Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Query returning 0 results [500 pts]

Posted on 2006-11-10
3
Medium Priority
?
267 Views
Last Modified: 2013-12-12
I created a table using the following code:

CREATE TABLE si_auth_user (
user_id VARCHAR(10) NOT NULL,
user_password CHAR(32) NOT NULL,

PRIMARY KEY (user_id)
);

INSERT INTO si_auth_user (user_id, user_password) VALUES ('guest', PASSWORD('guest'));
INSERT INTO si_auth_user (user_id, user_password) VALUES ('admin', PASSWORD('admin'));



When I try to run this query, I get 0 results returned:

SELECT user_id FROM si_auth_user WHERE user_id = 'guest' AND user_password = PASSWORD('guest')


What am I doing wrong?
0
Comment
Question by:dprundle
  • 2
3 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17918259
Your user_password field isn't long enough.

For that matter, it's not recommended to use the PASSWORD() function for user data anyway; use something like MD5().

To see what's going on, try just doing  SELECT PASSWORD('guest')
0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 2000 total points
ID: 17918267
mysql> select * from si_auth_user;
+---------+----------------------------------+
| user_id | user_password                    |
+---------+----------------------------------+
| guest   | *11DB58B0DD02E290377535868405F11 |
| admin   | *4ACFE3202A5FF5CF467898FC58AAB1D |
+---------+----------------------------------+
2 rows in set (0.00 sec)

mysql> select PASSWORD('guest');
+-------------------------------------------+
| PASSWORD('guest')                         |
+-------------------------------------------+
| *11DB58B0DD02E290377535868405F11E4CBEFF58 |
+-------------------------------------------+
1 row in set (0.00 sec)


Sure they don't match.  (-:
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17918405
VoteyDisciple has already revieled the problem that the ifled user_password is not long enough.
apart from that problem, you should NOT use CHAR() datatype, but rather VARCHAR(), in this case VARCHAR(100) for example

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question