When I open a CGI file in txt file and edit the code and save it and run it, it works as normal. But when I copy the code over to word doc and copy it back to the CGI file and save it and run it, it does not work. Why is that? I did not even make any changes to the code. Just copying to word doc and back and saving it and the CGI file does not work.
Word is a bit like HTML There's what you see, and then there's the "source code" When you copy back from Word you get all the Microsoft specific source code that comes with it and your cgi programme "can't deal" Paste into notepad, select all, copy and then save as the cgi file but no programming code should every go anywhere near a Word page, ever. There are much better editors out there like netbeans, sublimetext, notepad++, and even Microsoft's own notepad program
Most likely due to the line endings. For instance, on Unix the line endings are a Line Feed (\n) and on Windows it's a Carriage Return AND Line Feed (\r\n). Carriage Returns in a script on a Unix server will break. Wordpad replaces each Line Feed with a Carriage Return. This will break your script. You need a programmers editor like sarahk suggested.