Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.24 KB | None | 0 0
  1. #! C:\xampp\perl\bin\perl.exe
  2.  
  3. use CGI qw(:standard);
  4. use DBI;
  5.  
  6. print header;
  7. print start_html;
  8. print start_form;
  9. print p("Emp Number:",textfield("empno"));
  10. print p("Emp Name:",textfield("empname"));
  11. print p("Job Title", popup_menu(-name=>'empjob',-values=>['Programmer','Networker','SysAdmin','Customer Support'], -default=>['Programmer']));
  12. #print p (radio_group(-name=>'department',values=>['IT','Financial','Sale'],-default=>'IT'));
  13.  
  14.  
  15. print p(submit("Register"));
  16. print end_form;
  17.  
  18.  
  19. if(param()){
  20. #Read form data
  21. $EmpNo = param("empno");
  22. $EmpName = param("empname");
  23. $EmpJob = param("empjob");
  24. #$Department = param("Department");
  25. Insert_db();
  26. }
  27.  
  28. sub Insert_db{
  29. # Step 1: MySQL database: Declare DSN
  30. my $dsn = "DBI:mysql:as5-dylan";
  31. my $username = "root";
  32. my $password = '';
  33.  
  34. # Step 2:connect to MySQL database
  35. my $dbh  = DBI-> connect($dsn,$username,$password)
  36. or die("Error connecting to the database");
  37.  
  38. #Step 3: Pose an INSERT Query
  39. # A)Formulating the query
  40.  
  41.  
  42.  
  43. $query = "INSERT INTO emp(empno, empname, empjob) VALUES ($EmpNo, $EmpName, $EmpJob)";
  44.  
  45.  
  46. # B) Verify the Query
  47. $sth = $dbh->prepare($query);
  48. # C)Executing the Query
  49. $sth->execute();
  50.  
  51. # Step 4: Disconnect from the MySql Server
  52. $dbh->disconnect();
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement