我正在创建一个.cgi文件,它以表格格式打印网页上数据库表中的所有值.问题是,当我在putty终端模拟器上运行该文件时,它运行正常,但当我尝试在浏览器上运行该文件时,我得到了即使T在服务器上键入文件的正确位置,也会显示错误消息"找不到文件".
我无法理解我做错了什么?我使用putty将我的文件权限设置为chmod 755*,但它仍然无法正常工作.这是一个文件权限或表结构的问题是否在浏览器上运行是错误的?
请帮忙...
people.CGI文件
#!/usr/bin/perl
use CGI;
use DBI;
use strict;
#use warnings;
#use diagnostics;
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( my $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();
Run Code Online (Sandbox Code Playgroud)
数据库表结构......
表数据......
我在putty中运行文件时输出...
我尝试在浏览器上运行该文件时的消息..
Dav*_*oss 11
您之前收到的两个答案完全是胡说八道.您不需要使用CGI对象来运行CGI程序.当然,它使它更容易,但它没有必要.
程序需要处理的CGI协议的唯一部分是Content-Type标头.而你正在用你的印刷线做到这一点.
不,你的问题完全在别的地方.但是,不幸的是,在不知道更多的情况下,我们可以提供很少的帮助.您收到文件未找到错误,因为Web服务器找不到您的代码.换句话说,您在浏览器中键入的地址(128.9.45.170/~pankaj.yadav/Test/cgi/people.cgi)与Web服务器上的文件名不匹配.
这一切都归结为您的Web服务器的配置方式.Web地址如何映射到文件路径?我们不知道.只有您的Web服务器管理员才能确定答案.
如果查看Web服务器错误日志,您可能会得到一个线索.您将在日志中看到文件未找到错误,该错误将(希望)包含Web服务器尝试查找的实际文件路径.这可能会帮助您找出应该放置CGI程序的位置.
归档时间: |
|
查看次数: |
2203 次 |
最近记录: |