Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.40 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use DBI;
  3. use DBD::mysql;
  4.  
  5. print "content-type:  text/html \n\n";
  6.  
  7. #Config vars
  8.  
  9. $host = "localhost";
  10. $database = "<your database>";
  11. $tablename = "employee";
  12. $user = "<your user id>";
  13. $pw = "<your password>";
  14.  
  15.  
  16. local ($buffer, @pairs, $pair, $name, $value, %FORM);
  17.     # Read in text
  18.     $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
  19.     if ($ENV{'REQUEST_METHOD'} eq "GET")
  20.     {
  21.         $buffer = $ENV{'QUERY_STRING'};
  22.     }
  23.     # Split information into name/value pairs
  24.     @pairs = split(/&/, $buffer);
  25.     foreach $pair (@pairs)
  26.     {
  27.         ($name, $value) = split(/=/, $pair);
  28.         $value =~ tr/+/ /;
  29.         $value =~ s/%(..)/pack("C", hex($1))/eg;
  30.         $FORM{$name} = $value;
  31.     }
  32.     $phone = $FORM{fname};
  33.  
  34.  $lname  = $FORM{lname};
  35.     $job   = $FORM{job};
  36.     $state = $FORM{state};
  37.  
  38. print "<html>";
  39. print "<head>";
  40. print "<title>Adding</title>";
  41. print "</head>";
  42. print "<body>";
  43. print "<h2>Adding Employee  $fname $lname $job </h2>";
  44. print "</body>";
  45. print "</html>";
  46.  
  47.  
  48. #DATA SOURCE NAME
  49. $dsn = "dbi:mysql:$database:localhost:3306";
  50.  
  51. #PERL DBI Connect
  52. $connect = DBI->connect($dsn,$user,$pw)
  53.             or die "Unable to connect $DBI:errstr\n";
  54.  
  55. # PREPARE THE QUERY
  56. $query = "INSERT INTO employee (lname,fname,job) VALUES ('$lname','$fname','$job')";
  57. $query_handle = $connect->prepare($query);
  58.  
  59. # EXECUTE THE QUERY
  60. $query_handle->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement