I'm brand new to Perl and have tried researching how to submit data from a form into my MySQL database using Perl (.pl file) and can't get it to work. I created the form from a form creation tool of my web host, and it works when just sending the information in an email (and not the db). Now I'm trying to upload simple .pl files to my cgi-bin just to see if they would work to insert a simple row of data, and I can't even get those to work (get the internal server error). I have no idea what I'm doing wrong and have read through hundreds of examples with no luck. Here is a simple .pl file that I was trying to use just to see if it would work (I was trying to use a direct link to the .pl file, can you do that? e.g. www.sitename.com/cgi-bin/file.pl); can anyone help?? I'm very frustrated:
# HelloMySQL.pl # # MySQL STARTS HERE use strict; use CGI qw(:standard); use DBI; #MySQL CONFIG VARIABLES $host = "ftp here"; $database = "dbname here"; $tablename = "tablename here"; $user = "userid here"; $pw = "pw here"; # CONNECT TO DB $db = DBI->connect($host, $database, $user, $pw); # SELECT DB $db->selectdb($database); # DEFINE A MySQL QUERY $myquery = "INSERT INTO $tablename (fname, lname, street, city, state, zip, emai +l, age) VALUES ('fname1,'lname1','street1', 'city1', 'state1', ' +zip1', 'email1', 'age1')"; # EXECUTE THE QUERY FUNCTION $execute = $connect->query($myquery); $execute->execute(); # CLOSE DB CONNECTION $db->disconnect(); exit;
In reply to Need help connecting to MySQL from .pl by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |