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;
- print start_form;
- print p("Emp Number:",textfield("empno"));
- print p("Emp Name:",textfield("empname"));
- print p("Job Title", popup_menu(-name=>'empjob',-values=>['Programmer','Networker','SysAdmin','Customer Support'], -default=>['Programmer']));
- #print p (radio_group(-name=>'department',values=>['IT','Financial','Sale'],-default=>'IT'));
- print p(submit("Register"));
- print end_form;
- if(param()){
- #Read form data
- $EmpNo = param("empno");
- $EmpName = param("empname");
- $EmpJob = param("empjob");
- #$Department = param("Department");
- Insert_db();
- }
- sub Insert_db{
- # Step 1: MySQL database: Declare DSN
- my $dsn = "DBI:mysql:as5-dylan";
- my $username = "root";
- my $password = '';
- # Step 2:connect to MySQL database
- my $dbh = DBI-> connect($dsn,$username,$password)
- or die("Error connecting to the database");
- #Step 3: Pose an INSERT Query
- # A)Formulating the query
- $query = "INSERT INTO emp(empno, empname, empjob) VALUES ($EmpNo, $EmpName, $EmpJob)";
- # B) Verify the Query
- $sth = $dbh->prepare($query);
- # C)Executing the Query
- $sth->execute();
- # Step 4: Disconnect from the MySql Server
- $dbh->disconnect();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement