Strange thing, need some help! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Strange thing, need some help!

pennywallypennywally Posts: 4Member
As I said in an earlier thread, I'm making a guestbook with Perl and CGI. Just when the previous problem got solved, I ran into another ;)

This is the case. If I write a comment that is longer than the textbox's width, it makes a new post in the guestbook and set the characters that were left, in the Name spot.

I can't find out what the heck is wrong, so I hope that someone out there can help me.

This is an example of what happens.

[green]
# this is the second post, all these A's should be in the first post, on a new line after all the other A's ;-)
Name: aaaaaaaaaaaaaaaaaaaa
City:
E-mail:
Comments:

# this is the first post.
Name: aaaaa
City: aaaaa
E-mail: aaaaa
Comments: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
[/green]

Here is the full script. I wasn't sure on what to paste, so I took all of it.

[code]
#!/usr/bin/perl

use CGI;
$q = new CGI;
$name = $q->param('name');
$city = $q->param('city');
$email = $q->param('email');
$comments = $q->param('comments');
$action = $q->param('action');

if($action eq "spara") {
if ($name && $city && $email && $comments) {
open (LOG, ">>guestbook.log");
flock (LOG, 2);
seek (LOG, 0, 2);
print LOG "$name|$city|$email|$comments
";
close (LOG);
}

else {
print "Fill in all the fields please.";
}
}


open(GB, "guestbook.log");
@indata = reverse();
close (GB);

print "Content-type: text/html

";
print

Simons gstbok

TD {
FONT-FAMILY: verdana;
FONT-FACE: verdana;
FONT: verdana 8pt;
FONT-SIZE: 8pt; }

A {COLOR: black; TEXT-DECORATION: underline;}
A:hover {COLOR: black; TEXT-DECORATION: none;}
A:visited {COLOR: black; TEXT-DECORATION: underline;}
A:active {COLOR: black; TEXT-DECORATION: underline;}



";
print "
";
print "


Gstbok
















Namn:
Stad:
E-mail:
Kommentar:
HTML

foreach $rad (@indata) {
chomp($rad);
($name, $city, $email, $comments) = split(/|/,$rad);

print "


";
print "


";
print "
";
print "
";
print "
";
print "
";
print "
Name:$name
City:$city
E-mail:$email
Comments:$comments
";
print "


";
}

print "

";
print "
";
print "
";
[/code]




Comments

  • JonathanJonathan Posts: 2,914Member
    [code]
    : open (LOG, ">>guestbook.log");
    : flock (LOG, 2);
    : seek (LOG, 0, 2);
    : print LOG "$name|$city|$email|$comments
    ";
    : close (LOG);
    [/code]

    Scrub the seek line and it should work out for you. It looks to me like you're over-writing the start of the file with your new entry. If you want to put the latest entry at the top of the file you can't do it this way as it doesn't insert and shove the rest of the file forward, it overwrites.

    Note that you may have fun if $comments contains multiple lines... You can always s/
    /
    /g it though. What a hack...

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.