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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.