0

I am writing a php script to query a MYSQL database. However, I may have a syntax error that makes my code not work.

If I do not use a variable and subsitute $errType for 'version'(for example), everything works fine. I am having issues with using a variable in place for a field.

 $errType = $_POST['errorCategory'];
 $errType = $mysqli->real_escape_string($errType);

 $sql = "SELECT * FROM codecError WHERE '$errType' ='0' ";
 $result = $mysqli -> query($sql);
 $count = $result -> num_rows;

 if($count > 0){
 }
dave
  • 475
  • 6
  • 17

1 Answers1

0

Maybe you mean?

$sql = "SELECT * FROM codecError WHERE {$errType} ='0'";

You could also write it as

$sql = "SELECT * FROM codecError WHERE ".$errType." ='0'";
devpro
  • 16,184
  • 3
  • 27
  • 38
Bearzi
  • 538
  • 5
  • 18