-2

Error Output

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '//some values

I have a query like this:

$sql = "SELECT col1, col2 FROM table1
WHERE col1 = " . $row['value'] . "";

But if did my query hard code like this:

$sql = "SELECT col1, col2 FROM table1
WHERE col1 = 'string data (string data too)'";

it works as I expected.

Note that I have some values that has ( ) open and close parenthesis like I put in hard coded query above.

Also Note that $row['value'] returns correct value like I tested in the hardcoded query.

I am expecting the same output as in hardcoded query.

Emjey23
  • 339
  • 1
  • 4
  • 16

1 Answers1

1

If this query has a string data then it must be enclosed by quotes ' like as follow.check this query once.

$sql = "SELECT col1, col2 FROM table1
WHERE col1 = '" . $row['value'] . "'";
A.D.
  • 2,352
  • 2
  • 15
  • 25