0

I try to make a query so i can retrieve x1 as said in title (x1 is in int) but this error appears:

My php code:

echo "the food is:";
echo $food;
$query = "SELECT foodid FROM foods WHERE name = $food";
echo "the query is:";
echo $query;
$result_id = pg_query($conn,$query) or die("Query cannot be executed");

The error:

Warning: pg_query(): Query failed: ERROR: Column "burito" does not exist

I can not understand why somewhere between it turns to lower case.

In the result of echos the name Burito is shown Correct (with capital B). Any hint will be really helpful.

EDIT:

After I fixed this problem with the help of wogsland I noticed that if I echo the $result_id the outcome is

Resource id #8

But it supposed to be the number 149.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
prof chaos
  • 404
  • 3
  • 18

1 Answers1

0

You're missing single quotes in your SQL query around $food:

$query = "SELECT foodid FROM foods WHERE name = '$food'";

That's why when $food = 'burito' you're running into trouble. If there are no single quotes it assumes burito is a column name rather than a string.

wogsland
  • 9,106
  • 19
  • 57
  • 93