SELECT with various parameters in PHP

Asked

Viewed 1,092 times

0

Well what I intended was to make a select, with several parameters other than just 1.

$verifica = mysqli_query($link, "SELECT * FROM usuarios WHERE login='$login'");

In the case of the above code I only have 1 parameter which is if the login = $login, but I wanted to do to add more parameters, ie more conditions, such as age = $age. How can I do that?

Thank you.

  • "SELECT * FROM usuarios WHERE login='$login' AND idade = '$idade'" - if you want to add more just put the "AND", but it is not a good practice to pass the variables directly this way.

1 answer

2


Using OR or AND

If you want to add more attributes to filter your search you can use AND or. In case we will have:

// Para AND (Irá retornar apenas as tuplas que tem LOGIN E IDADE que você informou na query)

$verifica = mysqli_query($link, "SELECT * FROM usuarios WHERE login='$login' AND idade = '$idade'");

// Para OR(Irá retornar as tuplas que tem LOGIN OU IDADE que você informou na query)

$verifica = mysqli_query($link, "SELECT * FROM usuarios WHERE login='$login' OR idade = '$idade'");

Alert

This type of query is not safe because it makes room for the attack sql-Injection, take a look at the material below:

http://php.net/manual/en/security.database.sql-injection.php

Browser other questions tagged

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