0

I'm trying to set empty MySQL fields to NULL if all they contain is a line break.

if ($field === '\n') :
  $sql = "UPDATE table SET field = NULL
  WHERE id = '$id'
  ";
endif;

For some reason, it does not work. I did check the field, it only contains just one linebreak.

What could be a problem?

Steven
  • 157
  • 8

1 Answers1

1

Single quotes inhibit escape sequence replacement. Try "\n":

if ($field === "\n") {
  $sql = "UPDATE table SET field = NULL
  WHERE id = '$id'
  ";
}
knittl
  • 216,605
  • 51
  • 293
  • 340