0

I'm trying to make an address book that takes the data entered by a user in a form, and then sends it to a table in a database. I have no idea if I'm doing it right since I haven't found a whole example of html for and perl code - just snippets. I'm getting an error (I'll post it after the code).

<!doctype html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Address Book</title>
   <link rel="stylesheet" href="stylesheet.css">
 </head>

<body>
<h2>Address Book</h2>
<form action="test2.pl" name="myForm" method="post">
    <fieldset>
        <legend>Contact Details</legend>
        <div>
            <label for="First_Name">First Name:  </label>
            <input type="text" id="First_Name" name="First_Name" placeholder="John" required><br>
        </div>

        <div>
            <label for="Last_Name">Last Name:  </label>
            <input type="text" id="Last_Name" name="Last_Name" placeholder="Doe" required><br>
        </div>

        <div>
            <label for="Address">Address:  </label>
            <input type="text" id="Address" name="Address" placeholder="123 My Street Anytown, US 45678" required><br>
        </div>

        <div>
            <label for="Phone">Phone:  </label>
            <input <input pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" id="Phone" name="Phone" placeholder="(xxx)xxx-xxxx" maxlength="13" required> <br>
        </div>

        <div>
            <label for="Birthday">Birthday:  </label>
            <input type="date" id="Birthday" name="Birthday" value="" required><br>
        </div>

        <div>
            <label for="Email">Email:  </label>
            <input type="email" id="Email" name="Email" placeholder="johndoe@email.com" required><br>
        </div>

        <div>
            <label for="Relationship">Relationship:  </label>
            <input type="text" id="Relationship" name="Relationship" placeholder="brother" required><br>
        </div>

        <div>
            <input type="submit" value="Submit">
            <input type="reset" value="Reset">
        </div>
</form>
</body>
</html>

And perl code:

use strict;
use warnings;
use DBI;
print "HTTP/1.0 200 OK\n";
print "Content-Type: text/html\n\n\n";

 my $dbh=DBI->connect("DBI:mysql:database=address_book;host=**.**.***.159", "***", "****");
my $o = new CGI;

my $Contact_ID = $o -> param("Contact_ID");
my $First_Name = $o -> param("First_Name");
my $Last_Name = $o -> param("Last_Name");
my $Address = $o -> param("Address");
my $Phone = $o -> param("Phone");
my $Birthday = $o -> param("Birthday");
my $Email = $o -> param("Email");
my $Relationship = $o -> param("Relationship");

$dbh->do("INSERT INTO Contacts VALUES (?, ?, ?, ?, ?, ?, ?, ?)", undef, '0', $First_Name, $Last_Name, $Address, $Phone, $Birthday, $Email, $Relationship);


$dbh->disconnect();

The error:

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are "install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: C:/Program Files (x86)/Parallels/Plesk/Additional/Perl/site/lib C:/Program Files (x86)/Parallels/Plesk/Additional/Perl/lib .) at (eval 3) line 3. Perhaps the DBD::mysql perl module hasn't been fully installed, or perhaps the capitalisation of 'mysql' isn't right. Available drivers: CSV, DBM, ExampleP, File, Gofer, ODBC, Oracle, Proxy, SQLite, Sponge. at G:\PleskVhosts\tonyalesher.com\httpdocs\project\test2.pl line 7 HTTP/1.0 200 OK Content-Type: text/html ".

I downloaded the DBD from my command prompt, but I can't find the folder that it's mentioning - it doesn't exist on my computer. I'm using a godaddy account (plesk) I don't know if that matters. Thank you!

Borodin
  • 126,100
  • 9
  • 70
  • 144
TonyaL
  • 1
  • 1
    If you're running it on a Godaddy hosting account, then you need to install the module on the Godaddy computer, not your own. – Quentin Aug 29 '16 at 19:59
  • https://uk.godaddy.com/help/can-i-add-perl-modules-to-my-hosting-account-1488 – Quentin Aug 29 '16 at 20:00
  • You can't send an HTTP status line from CGI code. You can set the status using a `Status` header, but if you don't specify one then it defaults to `200`. To send that explicitly you would `print "Status: 200 OK\n"` but there is no need, and the only required header is `Content-Type`, which should be followed by *two* newlines, not three. – Borodin Aug 30 '16 at 01:54
  • `my $o = new CGI` won't work because you have no `use CGI`. You can print your `Content-Type` header using just `print $o->header`. – Borodin Aug 30 '16 at 01:56

1 Answers1

-1

The error you are getting is saying that DBD::mysql isn't installed where the instance of perl you are running is expecting it. Do you know if you are using ActiveState Perl, Strawberry Perl, or some other distribution?

With ActiveState, you are probably best served by using its repository of precompiled packages: ppm. The command to install a module is something like:

ppm install DBD::mysql

If you are using Strawberry Perl, then see this question.

Community
  • 1
  • 1
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
  • I am using ActiveState - when I enter that command in the command prompt it says that there are no missing packages to install. When I look in the Perl Package Manager, I can see DBD-mysql in the list. Is there something special I have to do to get that package into my godaddy web root folder besides the "use" statement in my .pl file? – TonyaL Aug 29 '16 at 21:46
  • @TonyaL When you look in PPM located _where_? – Matt Jacob Aug 29 '16 at 23:32
  • In the list of packages - I even also marked it then installed it. I called godaddy, and they said if I switched to the Linux type of account it should fix the problem. They deleted old account, started new one, I re-uploaded everything (and changed the host and sign in info in the code). I'm no longer getting that error - but now I'm getting a 500 internal error msg. Head -> desk. – TonyaL Aug 30 '16 at 00:17
  • @TonyaL Ah, I see your problem, you are installing Perl modules on your machine, not in your program. Copying your program up to a server won't take the modules with it. You need to install modules on the server as well, or use [App::Fatpacker](http://search.cpan.org/dist/App-FatPacker/lib/App/FatPacker.pm) or [PAR](http://search.cpan.org/dist/PAR/lib/PAR.pm) to bundle your dependencies with your program. – Chas. Owens Aug 31 '16 at 14:11