Variable in SQL query

Asked

Viewed 47 times

0

Guys, I’m trying to make a query with a variable that I’m receiving, but it’s not working. Any suggestions ?

$model = $_REQUEST['model'];
$customer = $_REQUEST['customer'];
SELECT * FROM sistema WHERE concluido <> 1 AND site='$site' AND $model='X'
  • What is the error? And these variables are coming correctly?

  • 3

    You’re very confused about this. You’re not using $Ustomer, instead you’re using $site. I didn’t understand if the sql string is like this and if you don’t know how to query the database or if it was just an example...

  • Tried to print the query and run straight into the bank?

  • 1

    I hope that $model is not what it seems...

1 answer

3


Elaborate as follows:

$model = $_REQUEST['model'];
$customer = $_REQUEST['customer'];

$consulta = "SELECT * FROM sistema WHERE concluido <> 1 AND site = '{$site}' AND {$model} = 'X'";

Do not forget to check if the variables are coming correctly and if really the comparison signal is <>, maybe you can use = '1'.

  • Sensational André, Thanks friend!!

Browser other questions tagged

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