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()) {
- if($Records eq false) {
- print table({-border=>1});
- print Tr;
- print th(['Employee Number','Name', 'Total','Registeration Date']);
- }
- $Records = true;
- print Tr;
- print td([$row[1], $row[2], $row[3], $row[4]]);
- }
- if ($Records) {
- print end_table;
- }
- 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