I solved the problem and apologize for the inconvenience. I overlooked a certain print 
statement which would be sent to the browser before printing a header under certain 
circumstances.

Thanks - Jan

Jan Eden wrote on 02.05.2004:

>Hi all,
>
>I initially posted this to the [EMAIL PROTECTED] mailing list,
>but it seems to be more of a CGI problem. This is the situation:
>
>1. My script (edit.pl) reads a row of data from a database and
>displays it in an html form for editing.
>
>2. On submitting, the same script is called (in 'commit' mode) to
>write the updated data to the database.
>
>3. After the update, another script (show.pl) is called to load the
>updated data and print it to the screen with my site's layout.
>
>Steps 1 and 2 always (!) work fine, even if the error occurrs.
>
>In most cases, step 3 also works fine. But if the content loaded
>from the database is quite long (or is not properly encoded in
>utf8), I get the "malformed header from script" error.
>
>Now there"s a funny thing: If I do not load the content itself (via
>a variable $content) from the database into the form field, but just
>print out the word "content" and paste the original content into the
>field, I never get the error.
>
>That's strange, since the content transferred as a CGI parameter
>should be the same in both cases: The original content. The only
>difference is the string printed to the form field when the form is
>generated.
>
>I experimented a bit. Simple strings (like "content") never cause an
>error. But if I add some tab stops and newlines, the error returns.
>
>So I have been able to track down the source of the problem, but I
>just cannot understand it.
>
>Could anybody help me here? Below you find some code from my
>script's code. I know it's less elegant than it could be and I
>already got some hints for fine tuning it, but I'd like to solve the
>serious problem first.
>
>Thanks,
>
>Jan
>
>---- #!/usr/bin/perl -w
>
>use strict; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); #
>mein Modul für user_check, mysql_config und headfoot use Site2;
>
>my $q = new CGI;
>
># Standardmodus ist lokal my $mode = $q->param('mode') || 'local';
>
># Konfiguration fuer die Verbindung zum MySQL-Server my ($server,
>$db, $username, $password) = mysql_config($mode); my $dbh =
>DBI->connect("dbi:mysql:$db:$server", $username, $password,  {
>RaiseError => 1 });
>
># checken, ob es sich um Edition oder Neueintrag handelt my $id =
>$q->param('id') || '';
>
># Einlesen des eingegebenen Benutzernamen und Passworts my
>$user_name_input = $q->param('user_name') || ''; my
>$user_password_input = $q->param('user_password') || '';
>
># legt fest, ob eine Maske ausgegeben oder die Daten uebertragen
>werden my $edit_mode = $q->param('edit_mode') || ''; # legt die
>Mutter des neuen Eintrags fest (wird von show.pl übergeben) my
>$mother_id = $q->param('mother_id');
>
># Abrufen des Titels der Mutterseite für das Menü my $query =
>"SELECT title FROM pages WHERE page_id = $mother_id"; my $sth =
>$dbh->prepare($query); $sth->execute(); my ($mother_title) =
>$sth->fetchrow_array; $sth->finish();
>
># Bestimmte Muttertitel werden nicht gedruckt (Home, Public,
>Private) $mother_title = $mother_id == 1 || $mother_id == 2 ||
>$mother_id == 2200 ? '' : '|' . $mother_title . '|';
>
>my $title = 'Editieren und Einfügen';
>
># Einlesen des Seitenkopfes und -fußes (in Abhängigkeit von
>verschiedenen Variablen) my ($page_head, $page_foot) =
>headfoot($title, $mother_id, $mother_title, $mode);
>
># Deklaration verschiedener Variablen (leer für Neueinträge) my
>($author_id, $content, $link, $page_type, $user_id, $pdf, $tex) =
>();
>
># Ausdruck des Headers und Seitenkopfes print
>$q->header(-type=>'text/html', -charset=>'utf-8'), $page_head unless
>$edit_mode eq 'commit';
>
># Wenn noch kein Benutzername/Passwort angegeben ist:
>Identifizierung # Wenn Identifizierung nur außerhalb des lokalen
>Modus gewünscht ist: "$mode eq 'local' ||" zum Konditional
>hinzufügen unless ($mode eq 'local' || $user_name_input &&
>$user_password_input) {
>print qq{<h1>Identifizierung</h1><p>Bearbeitungsfunktionen sind 
>passwortgeschützt. Bitte geben Sie Benutzernamen und Passwort
>ein.</p><form action="edit.pl" method="post"
>enctype="application/x-www-form-urlencoded"
>accept-charset="utf-8"><table><tr><td>Benutzer:</td><td><input
>type="text" name="user_name" value="" size="20"
>/></td></tr><tr><td>Passwort:</td><td><input type="password"
>name="user_password" size="20" /></td></tr></table><input
>type="hidden" name="id" value="$id" /><input type="hidden"
>name="mother_id" value="$mother_id" /><input type="hidden"
>name="mode" value="$mode" /> <input type="submit" value="Absenden"
>/></form>};
>}
># Wenn Benutzername/Passwort vorhanden sind: überprüfen (dito zum
>lokalen Modus) elsif ($mode eq 'local' || user_check(1,
>$user_name_input, $user_password_input, $mode)) {
># Abrufen des Datensatzes, wenn eine $id vorhanden ist if ($id) {
>print qq{<h2>Editieren</h2>}; my $query = "SELECT mother_id,
>author_id, title, content, link, 
>page_type, user_id, pdf, tex FROM pages WHERE page_id = $id";
>my $sth = $dbh->prepare($query); $sth->execute(); ($mother_id,
>$author_id, $title, $content, $link, $page_type, $user_id, 
>$pdf, $tex) = $sth->fetchrow_array;
>$sth->finish();
>}
># sonst: Festlegen der Standardwerte für den Neueintrag else { print
>qq{<h2>Neueintrag</h2>}; ($author_id, $page_type, $user_id, $pdf,
>$tex) = (1,2,0,0,0);
>}
>######## print out the form here ############# print qq{<form
>action="edit.pl" method="post" 
>enctype="application/x-www-form-urlencoded"
>accept-charset="utf-8"><input type="submit" value="Absenden"
>/><table><tr><td>Page_ID:</td><td><input type="text" name="id"
>value="$id" size="5" readonly 
>/></td></tr><tr><td>Mother_ID:</td><td><input type="text" size="5" 
>name="mother_id" value="$mother_id" 
>/></td></tr><tr><td>Author_ID:</td><td><input type="text" size="5" 
>name="author_id" value="$author_id"
>/></td></tr><tr><td>User_ID:</td><td><input type="text" size="5"
>name="user_id" value="$user_id" 
>/></td></tr><tr><td>Page_Type:</td><td><input type="text" size="5" 
>name="page_type" value="$page_type"
>/></td></tr><tr><td>Link:</td><td><input type="text" size="120"
>name="link" value="$link" 
>/></td></tr><tr><td>PDF:</td><td><input type="text" size="5"
>/>name="pdf" 
>value="$pdf" /></td></tr><tr><td>LaTeX:</td><td><input type="text"
>size="5" name="tex" value="$tex"
>/></td></tr><tr><td>Page_Title:</td><td><input type="text"
>size="120" name="title" value="$title" 
>/></td></tr><tr><td>Content:</td><td><textarea name="content"
>/>rows="30" 
>cols="120">$content</textarea></td></tr></table><input type="hidden"
>name="mode" value="$mode" /> <input type="hidden" name="user_name"
>value="$user_name_input" 
>/><input type="hidden" name="user_password"
>/>value="$user_password_input" /> 
><input type="hidden" name="edit_mode" value="commit" /></form>}; } #
>bei nicht erfolgreicher Identifizierung else {
>print qq{<h1>Falsches Passwort!</h1><p>Bitte verwenden Sie den 
>"Zurück"-Button Ihres Browsers, um die Eingaben zu korrigieren.};
>}
>print $page_foot unless $edit_mode eq 'commit';
>
># Übertragungsmodus # für erneute Überprüfung hinzufügen: "&&
>user_check(1, $user_name_input, $user_password_input, $mode)" if
>($edit_mode eq 'commit') {
># Übernahme der Parameter aus der Editierungs- bzw. Neueintragsmaske
>my $mother_id = $q->param('mother_id'); my $author_id =
>$q->param('author_id'); my $user_id = $q->param('user_id'); my
>$page_type = $q->param('page_type'); my $title =
>$dbh->quote($q->param('title')); my $content =
>$dbh->quote($q->param('content')); my $link =
>$dbh->quote($q->param('link')); my $pdf = $q->param('pdf'); my $tex
>= $q->param('tex');
>#   bei vorhandener ID: Update des Datensatzes
>if ($id) { my $query = "UPDATE pages SET mother_id = $mother_id,
>author_id = 
>$author_id, user_id = $user_id, page_type = $page_type, title =
>$title, content = $content, link = $link, pdf = $pdf, tex = $tex
>WHERE page_id = $id";
>my $sth = $dbh->prepare($query); $sth->execute(); $sth->finish();
>print $q->redirect("show.pl?mode=local&id=$id");
>}
>#   sonst: Einfügen eines neuen Datensatzes
>else { my $query = "INSERT INTO pages (mother_id, author_id,
>user_id, title, 
>content, link, page_type, pdf, tex) VALUES ($mother_id, $author_id,
>$user_id, $title, $content, $link, $page_type, $pdf, $tex)";
>my $sth = $dbh->prepare($query); $sth->execute(); $sth->finish();
>print $q->redirect("show.pl?mode=local&id=$mother_id");
>}
>}
>$dbh->disconnect; -- How many Microsoft engineers does it take to
>screw in a lightbulb? None. They just redefine "dark" as the new
>standard.
>
-- 
Hanlon's Razor: Never attribute to malice that which can be adequately explained by 
stupidity.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to