Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use DBI;
- use DBD::mysql;
- print "content-type: text/html \n\n";
- #Config vars
- $host = "localhost";
- $database = "<your database>";
- $tablename = "employee";
- $user = "<your user id>";
- $pw = "<your password>";
- local ($buffer, @pairs, $pair, $name, $value, %FORM);
- # Read in text
- $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
- if ($ENV{'REQUEST_METHOD'} eq "GET")
- {
- $buffer = $ENV{'QUERY_STRING'};
- }
- # Split information into name/value pairs
- @pairs = split(/&/, $buffer);
- foreach $pair (@pairs)
- {
- ($name, $value) = split(/=/, $pair);
- $value =~ tr/+/ /;
- $value =~ s/%(..)/pack("C", hex($1))/eg;
- $FORM{$name} = $value;
- }
- $phone = $FORM{fname};
- $lname = $FORM{lname};
- $job = $FORM{job};
- $state = $FORM{state};
- print "<html>";
- print "<head>";
- print "<title>Adding</title>";
- print "</head>";
- print "<body>";
- print "<h2>Adding Employee $fname $lname $job </h2>";
- print "</body>";
- print "</html>";
- #DATA SOURCE NAME
- $dsn = "dbi:mysql:$database:localhost:3306";
- #PERL DBI Connect
- $connect = DBI->connect($dsn,$user,$pw)
- or die "Unable to connect $DBI:errstr\n";
- # PREPARE THE QUERY
- $query = "INSERT INTO employee (lname,fname,job) VALUES ('$lname','$fname','$job')";
- $query_handle = $connect->prepare($query);
- # EXECUTE THE QUERY
- $query_handle->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement