A
giant robot might be warbling about warnings becasuse that code is truly scary. You're taking values from the user and injecting them directly into your SQL without even checking what they are. Madness.
You should, at least, use the
quote() method to keep things sensible, or placeholders as
Ryszard suggests.
For diagnostics, I would run the script from the command-line with parameters to see if you can replicate the problem there. It could be that your RDBMS isn't accepting connections.
Also, without linefeeds, you might have to set
$|++ to turn off buffering. Put this near the top of your program, if so required.