Is it against code to secure junction box using Liquid Nails?
Article 314.23(B) of the National Electrical Code, says that the enclosure must be rigidly supported.


  NEC 2008
  314.23 Supports.
  (B) Structural Mounting An enclosure supported from a structural member of a building or from grade shall be rigidly supported either
  directly or by using a metal, polymeric, or wood brace.


Whether or not liquid nails would meet this criteria may be up to interpretation, so it's best to check with your local inspector to determine if they'd allow it.

The other (better) option, would be to use an old work box. Which is allowed by subsection C of the same section.


  NEC 2008
  314.23 Supports.
  (C) Mounting in Finished Surfaces. An enclosure mounted in a finished surface shall be rigidly secured thereto by clamps, anchors,
  or fittings identified for the application.