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
  • 167
  • 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
  • 246,190
  • 53
  • 318
  • 364