我试图打印表格中的网页上的数据库表的所有值。我正在使用.cgi扩展名的perl文件。每当我尝试运行我得到的代码错误“全局符号需要明确包名”应显示的数据库表的.The行的onLoad但它不会发生..错误 - 全局符号需要明确的包名
我已经尝试了很多,但不明白什么是错的代码..
请帮助..
代码people.cgi文件..
个#!/usr/bin/perl
use CGI;
use DBI;
use strict;
use warnings;
print "Content-type:text/html\r\n\r\n";
#$q = CGI->new;
#print $q->header;
my $dsn = "DBI:mysql:Demo:localhost"; # Data source name
my $username = "mint"; # User name
my $password = "MINT123"; # Password
my $dbh;
my $sth; # Database and statement handles
$dbh = DBI->connect($dsn, $username, $password);
$sth = $dbh->prepare("SELECT * from people");
$sth->execute();
print "<h1>ganesh</h1>";
print "<table >
<tr>
<th>ID</th>
<th>Name of People Involved</th>
<th>Position</th>
<th>Roles(A user can have multiple roles)</th>
<th>Notes</th>
</tr>";
while($href = $sth->fetchrow_hashref) {
print "<tr>";
print "<td>$$href{'id'}</td>";
print "<td>$$href{'name'}</td>";
print "<td>$$href{'pos'}</td>";
print "<td>$$href{'role'} </td>";
print "<td>$$href{'notes'}</td>";
#print "<td><input type='text' value=\"$$href{'display_name'}\" id =\"dis-$$href{'windows_id'}\" readonly> </td>";
#print "<td><input type='text' value=\"$$href{'email_id'}\" readonly> </td>";
print "</tr>";
}
print "</table>";
$sth->finish();
$dbh->disconnect();
错误消息..
Global symbol "$href" requires explicit package name at people.cgi line 31.
Global symbol "$href" requires explicit package name at people.cgi line 34.
Global symbol "$href" requires explicit package name at people.cgi line 35.
Global symbol "$href" requires explicit package name at people.cgi line 36.
Global symbol "$href" requires explicit package name at people.cgi line 37.
Global symbol "$href" requires explicit package name at people.cgi line 38.
Execution of people.cgi aborted due to compilation errors.
我的MYSQL table..It的结构具有14个coloumns ......它里面没有数据...
在'while'循环中声明'$ href'与'my':'while(my $ href = ...)'。 – amon
我做到了这一点,并试图通过输入它的网址,其中包含它的位置在我的网页浏览器的服务器上运行该文件,但我收到消息“文件未找到”!! ......为什么? – Lucy
[全局符号需要显式包名称]的可能重复(http://stackoverflow.com/questions/3141412/global-symbol-requires-explicit-package-name) –