DeveloperSide.NET Forums

DeveloperSide.NET => Building a Web Server, for Linux => Topic started by: man_pio on April 16, 2005, 11:25:04 AM



Title: perl scripts malfunction
Post by: man_pio on April 16, 2005, 11:25:04 AM
Hi,

I have an issue with my scripts which goes thus:
I use Nvu html editor to design a form but when I click on the submit button, instead of the script running the script itself is displayed on another page.
I have allowed .cgi scripts in apache but it still gave the same error.

Please what am I doing wrong???
thanks in advance
Pious


Title: perl scripts malfunction
Post by: admin on April 16, 2005, 05:17:46 PM
Sounds like your "cgi" script has a bad or no "shebang" line...
http://www.devside.net/web/config/cgi

You might also need to 'script-alias' that dir under Apache.
And have PHP or Perl setup correctly.
Check Apache's error.log file.


Title: re: Perl malfunction
Post by: man_pio on April 17, 2005, 02:32:39 PM
hi,
thanks for your reply. I configured apache as stipulated in the link but still got the same error. here is a copy of my script pls. kindly edit and let me know wher I've gone wrong. I would have added the config of the httpd.conf file but it's too large to be pasted into this window. thanks.

#!/usr/bin/perl -w
                                                       
use CGI qw(:standard);
use DBI;

#setup database connection variables
$db = "weblinks";
$host = "localhost";
$user = "pious";
$password = "smokey";
                                                                             
#WEB form
print header;
print start_html('WEBLINKS DISPLAY');
print start_form,
      p
      "URL", textfield('url'),
      p
      "DESCRIPTION", textfield('description'),
      p,
      submit(-value=>"SUBMIT"),
      end_form,
      hr;

#Get Month information
my @month = ("01", "02", "03", "04", "05",
   "06", "07", "08", "09", "10",
   "11", "12");
                                                                               
#Get the date and time info
my ($Seconds, $Minutes, $Hours, $DayInMonth, $Month, $ShortYear,
   $DayOfWeek, $DayOfYear, $IsDST) = localtime(time);
# Fix the year for post-Y2K
my $Year = $ShortYear + 1900;
my $EntryDate = "$Year:$month[$Month]:$DayInMonth";
my $EntryTime = "$Hours:$Minutes:$Seconds";
                                                                               
#Create variable for form
my $URL = param('url');
my $DESCRIPTION = param('description');                                        

#ensure that text fields are filled
if (param('url') && param('description'))
{
print " ";
}
elsif (param() && param('description'))
{
print "Please enter URL!!";
}
elsif (param('url') && param())
{
print "Please enter DESCRIPTION!!";
}
else
{
print " ";
}

#connect to Database
my $dbh=DBI->connect("DBI:mysql:database=$db:host=$host", $user, $password) or die "Can't connect to database:$DBI::errstr\n";

#inserting entries
$dbh->do("INSERT IGNORE INTO link_info (URL, DESCRIPTION, DATESTAMP, TIMESTAMP) VALUES(?,?,?,?)", undef, (param('url'), param('description'), $EntryDate, $EntryTime));

$dbh->do("ALTER IGNORE TABLE link_info ADD UNIQUE URL (URL, DESCRIPTION)");

$dbh->do("DELETE FROM link_info WHERE URL = ' ' OR DESCRIPTION = ' '");

my $state = "SELECT * FROM link_info ORDER BY link_id DESC";
my $sth = $dbh->prepare($state);
$sth->execute( );
                                                                               
$sth->bind_columns ( undef,\link_id, \$URL, \$DESCRIPTION, \$EntryDate, \$EntryTime );
                                                                               
while ( $sth->fetchrow_array( ) ) {
if (param('url') && param('description'))
{
         print start_html(),
             p td($URL),
               td("<a target=_blank href=http://$URL>$DESCRIPTION</a>"),
               td($EntryDate),
               td($EntryTime),
           end_html;
}
}
$sth->finish( );
$dbh->disconnect();
exit;


Title: perl scripts malfunction
Post by: admin on April 17, 2005, 05:19:00 PM
If the source code of the script is displayed, its not a script problem.  Its a configuration problem.