Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.66 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. while (@row = $sth->fetchrow_array()) {
  46.  
  47.   $Username=$row[0]; #read first field from table
  48.   $EMPLOYEE=$row[1]; #read second field from table
  49.   $Total=$row[2]; #read third field from table
  50.   $DATE=$row[3]; #read fourth field from table
  51.  
  52.  
  53.   $tableContents = $tableContents + $row[0] + $row[1] + $row[2] + $row[3];
  54.  
  55.    $tableContents = true;
  56.  
  57. }
  58.  
  59. if ($tableContents) {
  60.     print table({-border=>1}); #Create HTML-Table
  61.         print Tr; #Add a row
  62.             print th(['Employee Number','Name', 'Total','Registeration Date']); # Display Table Header (1st row)
  63.  
  64.  
  65.  print Tr; #add new row to HTML_Table
  66.   print td(["$Username","$EMPLOYEE","$Total","$DATE"]); #Display records in the Table Columns
  67.  
  68. }
  69.  
  70. else {
  71.   print "No records found";
  72. }
  73.  
  74. # Step 4: Disconnect from the MySql Server
  75. print end_html;
  76. $dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement