Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何添加从数据库获取数据id的按钮并执行操作_Html_Perl - Fatal编程技术网

Html 如何添加从数据库获取数据id的按钮并执行操作

Html 如何添加从数据库获取数据id的按钮并执行操作,html,perl,Html,Perl,我正在制作一个连接到数据库“peoples”的代码,从那里获取数据,我需要做的是使用一个按钮获取单击该按钮的人的id,并删除或更新。问题是我不知道如何在perl中实现这一点,因为在其他语言中我做到了 my $q= new CGI; print $q->header; print $q-> start_html( -title => "Main", -style => {-src =>'/media/css/ui-lightness/jquery-

我正在制作一个连接到数据库“peoples”的代码,从那里获取数据,我需要做的是使用一个按钮获取单击该按钮的人的id,并删除或更新。问题是我不知道如何在perl中实现这一点,因为在其他语言中我做到了

my $q= new CGI;

print $q->header;
print $q-> start_html(
   -title   => "Main",
   -style  => {-src =>'/media/css/ui-lightness/jquery-ui-1.10.3.custom.css" rel="stylesheet' },
   -script => [ 
        { -src=>'/media/js/jquery-1.9.1.js'},
        { -src=>'/media/js/jquery-ui-1.10.3.custom.js' }
   ]
);

print $q->start_form;
print $q->table({},
        $q->Tr(
            $q->th('Name', 'Surname', 'Age')
        ));   


# Connect to the database

## mysql user database name
my $db = "student";
## mysql database user name
my $user = "root";

## mysql database password
my $pass = "";

## user hostname : This should be "localhost" but it can be diffrent too
my $host="127.0.0.1";

## SQL query
my $query = "select Name,Surname,Age from student";

my $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
my $sqlQuery  = $dbh->prepare($query)
or die "Can't prepare $query: $dbh->errstr\n";

my $rv = $sqlQuery->execute
or die "can't execute the query: $sqlQuery->errstr";

while ( my ($Name, $Surname, $Age) = $sqlQuery->fetchrow_array() ) {
     print STDOUT "$Name  $Surname $Age";
        $q->button( print $q->button(
        -id       => 'leletebtn',
        -name     => 'submit_form',
        -value    => 'Delete',
        )          
    )
}

print $q->end_form;  
print $q->end_html;

有很多教程。您必须使用DBI:


它是连接的,第一个代码可以工作,但delete.pl不能。请尝试编辑我的代码,如果你发现哪里是错误的。我是perl新手“您必须使用DBI”-这当然是一个非常好的主意,但我认为您并非绝对必须:-)除非您知道自己在做什么,否则您绝对应该使用DBI?:-)
my $lastname = 'test';

my $dbh = DBI->connect('DBI:Oracle:people')
                or die "Couldn't connect to database: " . DBI->errstr;#connect
my $sth = $dbh->prepare('SELECT id,uid FROM people WHERE lastname = ?')
                or die "Couldn't prepare statement: " . $dbh->errstr;#prepare
$sth->execute($lastname); # Execute the query
while ( my $ref = $sth->fetchrow_hashref() ) {
   print "$$ref{'id'} \t $$ref{'uid'}\n";
}