PDA

View Full Version : Simple CGI question


RandomGuy
07-16-2008, 05:58 AM
I just wrote a script for a bball tourney that we're throwing... the code is SUPER DUPER simple...

I have a question, how can I make it so a new entry does not overwrite the old one thats already in the html file. please dont mind my crude crude simple code :)

#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
my $tname = param('Teamn1');
my @players;
push(@players,param("Player1"), param("Player2"),

param("Player3"), param("Player4"), param("Player5"));
my $cname = param('name1');
my $numbr = param('phon1');
open(OUT, ">../registrants.html")or &dienice("Couldn't

open output file: $!");
print header;
print start_html("BBall Tourney Registration");
print h2("Thank you for registering, Hope to see you soon");
print OUT "<b>Team Name:", $tname,

"</b>&nbsp;&nbsp;&nbsp; ";
my $i;
for ($i = 0; $i < 5; $i++) {
print OUT @players[$i], "&nbsp;&nbsp;&nbsp; ";
}
print OUT "<br> Contact: ", $cname, "&nbsp;&nbsp;&nbsp; ",

$numbr, "<br><br><br><br>";
close(OUT);

whenever i test it and register a new team, it will over write the previously registered team instead of just adding it underneath and making a nice list

RandomGuy
07-16-2008, 06:36 AM
I figured it out reading through my books

For reference... if it helps anyone (which I doubt anyone is that dumb lol)

but I put
open(OUT, ">../registrants.html")or &dienice("Couldn't

open output file: $!");

instead of

open(OUT, ">>../registrants.html")or &dienice("Couldn't

open output file: $!");

> is used to overwrite data

and >> is used to ammend it, which is what I wanted.

THANKS AGAIN!!