M
M
marq2020-01-14 11:21:30
PHP
marq, 2020-01-14 11:21:30

The request is not executed, how to write it correctly?

have a request

$result = $connect->query("SELECT * FROM pag WHERE (id='$id' and name='$name') or (id='$id' or name='$name')");

$id and $name are passed as arguments.
for some reason, only this part works (id='$id' or name='$name')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2020-01-14
@marq

Either
or
in the current form the request does not make sense.
And to work with the database, you do not need to shove variables directly into the request, but use placeholders

S
Stimulate, 2020-01-14
@Stimulate

$result = $connect->query("SELECT * FROM pag 
WHERE 
(
  (id='$id') 
  AND 
  (name='$name')
)
OR 
(
  (id='$id') 
  OR
  (name='$name')
)
");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question