Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.31 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("Search Form with template");
  7. print start_form;
  8. print p("Enter your name",textfield("CName"));
  9. print p(submit("Search"));
  10. print end_form;
  11. if(param()){
  12. #Read form data
  13. $Search = param('CName');
  14. Insert_db();
  15. }
  16.  
  17. sub Insert_db{
  18. # Step 1: MySQL database: Declare DSN
  19. my $dsn = "DBI:mysql:e-Shop";
  20. #default admin username/Password  in mysql
  21. my $username = "root";
  22. my $password = '';
  23.  
  24. # Step 2:connect to MySQL database
  25. my $dbh  = DBI-> connect($dsn,$username,$password) ;
  26.  
  27. #Step 3: Pose an INSERT Query
  28. # A)Formulating the query
  29. $query = "SELECT * FROM `invoice` WHERE `CustName` like '$Search%'";
  30. # B) Verify the Query
  31. $sth = $dbh->prepare($query);
  32.  
  33.  
  34.  
  35. }
  36. # C)Executing the Query
  37. $sth->execute();
  38.  
  39. #########
  40.  
  41.  
  42.  
  43. $tableContents="";
  44.  
  45.  
  46. while (@row = $sth->fetchrow_array()) {
  47.     if($Records eq false) {
  48.         print table({-border=>1});
  49.         print Tr;
  50.         print th(['Employee Number','Name', 'Total','Registeration Date']);
  51.     }
  52.  
  53.     $Records = true;
  54.  
  55.     print Tr;
  56.     print td([$row[1], $row[2], $row[3], $row[4]]);
  57. }
  58.  
  59. if ($Records) {
  60.   print end_table;
  61. }
  62. else {
  63.   print "No records found";
  64. }
  65.  
  66. # Step 4: Disconnect from the MySql Server
  67. print end_html;
  68. $dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement