Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate entries in database query 1

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hello guys ! Ok , so here I am with a question that I hope won't be too dificult - after a few tries I haven't managed this time to get it fixed only managed to bypass it - but I'm a kinda newbie in php for now. The problem is this:

As an example = You have 2 entries in your database:

1.Anne Green password
2.John Smith Password->(duplicate password as above)

-----

1 and 2 as `IDs` ,John and Anne as `name` , Green and Smith as `surname` and Password as `password` fields. When I log in as Anne Green with Password the query says that password is correct but the name is wrong - since both people have the same password. When I change ORDER BY id ASC only Anne Green can be logged in not John Smith...I would be muchly grteful if someone passed me an example when one can be looged in with the same ( duplicate ) password. I've bee trying LIKE and WHERE commands but to no avail now. I know the passwords should be not duplicated but I need a solution in this case if possible - Thank you muchly guys...
 
This is of course more of a MYSQL question than PHP.

Now I'm guessing here, because you have provided no code, but obviously if you have the same password more than once,
and you run a query on the password field, you'll get several records back to check. If you limit those records you are missing out on potential matches.

Either loop through all the results hoping to find a match, or make a more specific query that yo can be sure will only ever return a single record.

You would want instead to perform a query to match all inputs, not just the password.

Code:
SELECT *FROM mytable WHERE name='inputname'  AND `password`='inputpassword' AND ...;

This should in most cases produce a single record.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi Phil - maxi thanks as usual...yes indeed - I just needed a bit "...WHERE `firstname`='".$_POST['firstname']."'"

That seems to solve the problem with duplication now.
 
Glad I could help.

May I suggest cleansing the POST variables before using them in a query. As it is you are exposing yourself to possible sql injection attacks.

Use at the very least mysql_real_escape_string() around $_POST variables.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Yes thanks - I've already used them throughout the pages. I'll post the address of the complete site soon. Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top