SELECT with several parameters in PHP

0

Well, what I wanted was to do 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 that 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 this?

Thank you.

    
asked by anonymous 09.04.2016 / 15:08

1 answer

2

Using OR or AND

If you want to add more attributes to filter your search you can use the AND or the 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 secure because it makes space for the sql-injection attack, take a look at the material below:

link

    
09.04.2016 / 15:46