0

I have a string saved in a variable. That string is made from a couple other variables. If I echo it to a test page it shows up correctly, but if I try to update a mysql table with that variable it doesn't work.

It update the table, however when I use the actual string and no the variable.

Works:

$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$conn->query("UPDATE db SET columnx = 1 WHERE columny = 'y'");

Does not work:

$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$y = 'y';
$columnx = 'columnx';
$conn->query("UPDATE db SET $columnx = 1 WHERE columny = '$y'");

I've been at this for 2 days and still can't figure out why these strings are not being loaded to the table when I use a variable.

Any help is, as always, greatly appreciated!

Eric Brockman
  • 824
  • 2
  • 10
  • 37

0 Answers0