INSERTs are not dangerous. Still, it's always a good idea to run addslashes() on data coming from the outside before passing it on to the database. Unless PHP's magic_quotes_gpc feature (I'd call it a mis-feature*) is turned on.
A suggestion for a code improvement:
$SQLnam=addslashes($nam);
$SQL="
INSERT INTO table(name)
VALUES ('$SQLnam')
";
*Note:
The magic_quotes_gpc feature is good for new PHP-programmers because they tend to forget to use addslashes(). However, in my opinion, the 'feature' is a source of frustration: I want my outside variables /as is/; I don't want PHP to change the data; but then I also have to take the responsibility to make proper conversions when needed.
To find out if magic_quotes is turned on: Look at the output from a phpinfo() call.