Variable to call where to search in the database!

Asked

Viewed 42 times

0

Does anyone know if it is possible for me to do a database search using a variable like the name of where to search in the database, like how it follows:

$consulta = mysqli_query($link, "SELECT * FROM alunos WHERE $turma = '$grupo'");

Where the variable $turma would be defined by the user.

  • 1

    What will contain in the variable $turma? Is the name of the column in the table ?

  • @wmsouza yes, in the variable $turma would be the column name in the table!

  • 2

    Apart from the huge security problem, is having some problem?

  • 2

    Your code seems to work, I don’t understand your question.

  • @Maniero I was having a problem yes, but it was the position of my form, reviewing the code I saw this error of mine, now it worked. I am new to SQL, this is the way I learned in the course, you would indicate me some material or video class to learn better about this security issue and make the site safer?

  • @Francisco It was a problem with the FORM, then the code was not running, and as I didn’t realize it was in the consultation, thank you!

  • 1

    If you want a course indication suggest this to no longer use the mysqli: https://www.youtube.com/watch?v=etRFu_eJ3vU&list=PLbXvLovKLUIkE78UNFE8UpfOtoDlrpQec

  • @Laérciolopes thank you very much, I will research on PDO, I had heard about, but I have not yet had to dig deeper, I will do this!

  • 1

    There’s video lessons on the Youtube link I posted

  • Yes, I will use them, they seem to be very good, thank you very much!

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.