$code = str_replace("\n","<br>",$row['code']);
You could replace this with a call to [man]nl2br[/man]
Have you looked at the generated HTML source, or just at the browser's attempt to render it?
'<textarea type="text", readonly="readonly", style="height:300px; width:400px;>"'
You might want to check where your quote marks in this string are (especially toward the end) - oh, and there shouldn't be commas between the attributes (while I'm still being pedantic, I'll add that the <textarea> element doesn't have a type= attribute).