单击提交按钮时,应调用回调函数。打印回调期间传递的所有参数不起作用。但它进入回调函数。如何访问传递的变量以便我可以插入表中。
sub registerStu {
use DBI;
use strict;
my $reg = $mw->Toplevel();
$reg->title("Registration");
$reg->geometry("500x500+0+0");
#$button -> grid(-row=>5, -column=>5);
my $name = $reg->Label( -text => "Name", -width => 20 )->pack( -side => "top" );
my $ename = $reg->Entry( -width => 20, -background => 'white', -foreground => 'black' )->pack( -side => "top" );
my $uid = $reg->Label( -text => "User name", -width => 20 )->pack( -side => "top" );
my $euid = $reg->Entry( -width => 20, -background => 'white', -foreground => 'black' )->pack( -side => "top" );
my $pwd = $reg->Label( -text => "Password", -width => 20 )->pack( -side => "top" );
my $epwd = $reg->Entry( -width => 20, -background => 'white', -foreground => 'black' )->pack( -side => "top" );
my $mail = $reg->Label( -text => "Email", -width => 20 )->pack( -side => "top" );
my $email = $reg->Entry( -width => 20, -background => 'white', -foreground => 'black' )->pack( -side => "top" );
my $dept = $reg->Label( -text => "Department", -width => 20 )->pack( -side => "top" );
my $edept = $reg->Entry( -width => 20, -background => 'white', -foreground => 'black' )->pack( -side => "top" );
my $gname = $ename->get();
my $guid = $euid->get();
my $gpwd = $epwd->get();
my $gmail = $email->get();
my $gdept = $edept->get();
my $submit = $reg->Button(
-text => "Register",
-command => sub { &InsertStu( $gname, $guid, $gpwd, $gmail, $gdept ); }
)->pack( -side => "top" );
}
sub InsertStu {
print "hello";
print "@_\n";
my $driver = "mysql";
my $database = "course";
my $dsn = "DBI:$driver:database=$database";
my $userid = "root";
my $password = "pwd";
my $dbh = DBI->connect( $dsn, $userid, $password, { AutoCommit => 1 } ) or die $DBI::errstr;
#my $sth = $dbh->prepare("INSERT into student(sid,name,password,email,dept) values('$guid','$gname','$gpwd','$gmail','$gdept')");
#$sth->execute() or die $DBI::errstr;
}