Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.92 KB | None | 0 0
  1. #! C:\xampp\perl\bin\perl.exe
  2.  
  3. use CGI qw(:standard);
  4. use DBI;
  5. print header;
  6. print start_html;
  7. print start_form;
  8. print p("Emp Number:",textfield("EmpNo"));
  9. print p("Emp Name:",textfield("EmpName"));
  10. print p(submit("Submit Form"));
  11. print end_form;
  12. if(param()){
  13. #Read form data
  14. $EmpNo = param("Emp Number");
  15. $EmpName = param("Emp Name");
  16. Insert_db();
  17. }
  18.  
  19. sub Insert_db{
  20. # Step 1: MySQL database: Declare DSN
  21. my $dsn = "DBI:mysql:as5-dylan";
  22. #default admin username/Password  in mysql
  23. my $username = "root";
  24. my $password = '';
  25.  
  26. # Step 2:connect to MySQL database
  27. my $dbh  = DBI-> connect($dsn,$username,$password) ;
  28.  
  29. #Step 3: Pose an INSERT Query
  30. # A)Formulating the query
  31. $query = "INSERT INTO emp ('EmpNo', 'EmpName') VALUES ('$EmpNo','$EmpName')";
  32. # B) Verify the Query
  33. $sth = $dbh->prepare($query);
  34. # C)Executing the Query
  35. $sth->execute();
  36.  
  37. # Step 4: Disconnect from the MySql Server
  38. $dbh->disconnect();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement