Advertisement
Guest User

Untitled

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