Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! C:\xampp\perl\bin\perl.exe
- use CGI qw(:standard);
- use DBI;
- print header;
- print start_html("Search Form with template");
- print start_form;
- print p("Enter your name",textfield("CName"));
- print p(submit("Search"));
- print end_form;
- if(param()){
- #Read form data
- $Search = param('CName');
- Insert_db();
- }
- sub Insert_db{
- # Step 1: MySQL database: Declare DSN
- my $dsn = "DBI:mysql:e-Shop";
- #default admin username/Password in mysql
- my $username = "root";
- my $password = '';
- # Step 2:connect to MySQL database
- my $dbh = DBI-> connect($dsn,$username,$password) ;
- #Step 3: Pose an INSERT Query
- # A)Formulating the query
- $query = "SELECT * FROM `invoice` WHERE `CustName` like '$Search%'";
- # B) Verify the Query
- $sth = $dbh->prepare($query);
- }
- # C)Executing the Query
- $sth->execute();
- #########
- $tableContents="";
- while (@row = $sth->fetchrow_array()) {
- $Username=$row[0]; #read first field from table
- $EMPLOYEE=$row[1]; #read second field from table
- $Total=$row[2]; #read third field from table
- $DATE=$row[3]; #read fourth field from table
- $tableContents = $tableContents + $row[0] + $row[1] + $row[2] + $row[3];
- $tableContents = true;
- }
- if ($tableContents) {
- print table({-border=>1}); #Create HTML-Table
- print Tr; #Add a row
- print th(['Employee Number','Name', 'Total','Registeration Date']); # Display Table Header (1st row)
- print Tr; #add new row to HTML_Table
- print td(["$Username","$EMPLOYEE","$Total","$DATE"]); #Display records in the Table Columns
- }
- else {
- print "No records found";
- }
- # Step 4: Disconnect from the MySql Server
- print end_html;
- $dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement