Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

malformed header from script

Status
Not open for further replies.

martinasv

Technical User
Feb 12, 2006
24
0
0
HR
Hello!

I have a strange thing going on. This is my perl code:
______________________________________
#! /usr/bin/perl
use CGI;
use DBI;

print "Content-type: text/html\n\n";
print "<HTML><HEAD><meta http-equiv=Content-Type content=text/html; charset=iso-8859-2><TITLE> Adding a NIC card name</TITLE></HEAD>";
print "<BODY BGCOLOR=EEEEEE>";

$username = 'root';$password = '';$database = 'arp';$hostname = '';
$dbh = DBI->connect("dbi:mysql:database=$database;" .
"host=$hostname;port=3306", $username, );

my $q=new CGI;
$MAC=$q->param("id");
#print "MAC: $MAC\n";

print "<HR>";
print "<H2><B><font color=\"#800000\"> All data about $MAC </font></B></H2>";



#creating HTML table
print "<BR><BR>";
print "<TABLE ALIGN=center WIDTH=50% BORDER=4 CELLSPACING=2 CELLPADDING=2>";

print "<tr> <th align=center valign=middle> MAC </th>";
print "<th align=center valign=middle> NIC name </th>";
print "<th align=center valign=middle> Computer name /th>";
print "<th align=center valign=middle> IP </th>";
print "<td align=center valign=middle> date </td>";
print "<td align=center valign=middle> time </td>";
print "</tr>";

$SQL="select * from table where MAC='$MAC' order by date";
$Select = $dbh->prepare($SQL);
$Select->execute();

while($Row=$Select->fetchrow_hashref)
{
print "<tr><td>$Row->{MAC} </a> <td>$Row->{NICname} <td>$Row->{CompName} <td>$Row->{IP} <td>$Row->{date} <td>$Row->{time}</tr>";

$mac1=$Row->{MAC};
$nameMAC=$Row->{NICname};
}

print "</TABLE>";

if ($NICname eq '')
{
print "<FORM action=\"/cgi-bin/NICname.pl\" method=post>";
print "<input type=text size=20 name=\"name\">";
print "<INPUT TYPE=submit NAME=submit value=\"Save\">";
print "</FORM>";
}

print "</BODY></HTML>";
______________________________________

When I check it from command line:
perl -wc myscript.pl
it says everything's ok.
But when I run it as html, I get Internal Server Error. And in Error_log file it says: malformed header from script. Bad header=name=myNIC&submit=Save: ...

Any ideas why this is happening and how to fix it?
 
instead of
Code:
print "Content-type: text/html\n\n";
print the header using the CGI module.
Code:
#! /usr/bin/perl
use CGI;
use DBI;

#print "Content-type: text/html\n\n";

$username = 'root';$password = '';$database = 'arp';$hostname = '';
$dbh = DBI->connect("dbi:mysql:database=$database;" .
  "host=$hostname;port=3306", $username, );

my $q=new CGI;
[COLOR=red]print $q->header();[/color]
#print "<HTML><HEAD><meta http-equiv=Content-Type content=text/html; charset=iso-8859-2><TITLE> Adding a NIC card name</TITLE></HEAD>";
print $q->start_html(-title=>'Adding a NIC card name',
               -style=>{'src'=>'/stylesheet/style.css'},
               -base=>'true',
               -target=>'_blank',
               -meta=>{'keywords'=>'pharaoh secret mummy',                   'copyright'=>'copyright 1996 King Tut'},
               -author=>'name or email address of author',
               -BGCOLOR=>'#EEEEEE');

HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks for the advice, PaulTEG!

It was very helpful - it got me started. But I had to print the whole form using the CGI module, as well.

Now it's working. [thumbsup2]
 
Good stuff

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top