2

is there a possible way to have a select as an answer?, i'm trying to do this in MySql but it always appear as an error:

//administrador and informacion are tables. //inmobiliaria is the schema.

SELECT if(administrador.usuario='Admin0'&&administrador.password='pass123', 
select * from inmobiliaria.informacion, null) FROM inmobiliaria.administrador;

at the end i'm trying to get everything from the table "informacion" if the password and the user from the administrador table are the same as the typed in the text boxes, but i haven't found the way.

10
  • 2
    Sample data and desired results would really help. Commented Mar 18, 2018 at 15:21
  • Do you have relation between administrador and informacion table ? Commented Mar 18, 2018 at 15:26
  • Looks like you are validating if the userid is Admin0 and password is correct. So you put the if statement first then do the select statement. You cannot do both at the same time. Commented Mar 18, 2018 at 15:28
  • There's no relation between administrator and informacion as i intended to use it for a log in a hidden form and the informacion would just be a simple editable gallery. should there be one? Commented Mar 18, 2018 at 15:30
  • 2
    DO NOT store passwords as plain text! Hash with salt. Commented Mar 18, 2018 at 15:36

1 Answer 1

1

It's kinda hard to tell what you want, but I think that your goal is something like select everything from inmobiliaria.informacion if the username and password are correct, or return null.

Please note that storing password as plain text in the database is a really, really bad idea. You should never store passwords as plain text. The correct way to handle passwords is to store a salted hash, so that even if someone would hack your database, the passwords can't be reverse engendered. For more information, read Salted Password Hashing - Doing it Right.

You can do something like this:

SELECT <ColumnsList>
FROM inmobiliaria.informacion
WHERE EXISTS
(
     SELECT 1
     FROM administrador
     WHERE usuario='Admin0'
     AND password='pass123'
)

This will return an empty result set if the user and password don't match.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much! it works!, indeed, that's what i was trying to do, i'm sorry if i didn't express myself well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.