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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question, what's wrong?

Status
Not open for further replies.

CircleStudios

Programmer
Joined
Jun 29, 2007
Messages
1
Location
US
I have 2 files, the 1st file is named ps.pl the 2nd file is named create.cgi My problem is this, my cgi page is suppose to add new information to the end of a text file, well it doesn't do that. Instead, it overwrites the entire text file, why?

Please help me fix that, please?

Below is the code I use!

In the ps.pl I have this:
----------------------------------------------------------

#!"C:/program files/apache2triad/perl/bin/perl.exe"
use CGI::Carp qw/fatalsToBrowser/;

$file_path = "C:/program files/apache2triad/htdocs/vhosts/playsoft/files/";

$c_login = 0;
$c_pass = 1;
$c_junk = 2;

sub savemember{
my($lname) = shift(@_);
my($fname) = $file_pathb.$lname.".txt";
my($line,$key);
my(@list);

open(FILE,">$fname") or error("Unable to open $fname"),exit;
@keys = keys(%roster);
foreach $key (@keys){
$line = $key;
for($x=0;$x<25;$x++){
$line = $line."\t$roster{$key}[$x]";
}
print FILE "$line\n";
}
close(FILE);;
}

sub error{
print "Content-type: text/html\n\n";
print "error\n";
exit;
}

---------------------------------------------------------



In the create.cgi file I have this:
------------------------------------------------------
#!"C:/program files/apache2triad/perl/bin/perl.exe"
use CGI::Carp qw/fatalsToBrowser/;
push(@INC,"C:/apache2triad/htdocs/vhosts/playsoft/");
require('ps.pl');

use CGI;
$cgi = new CGI;


if($ARGV[0] eq 'create'){
if($cgi->param('login')){
$login = $cgi->param('login');
$pass = $cgi->param('pass');
$junk = $cgi->param('junk');
if($login eq $cgi->param('login')){
$data = 'ccc';
$roster{$login}[$c_login] = $login;
$roster{$login}[$c_pass] = $pass;
$roster{$login}[$c_junk] = $junk;
savemember($data);
print "Content-type: text/html\n\n";
print <<EOF;
$roster{$login}[$c_login]
$roster{$login}[$c_pass]
$roster{$login}[$c_junk]
EOF
exit;
}
}

}

print "Content-type: text/html\n\n";
form();


sub form{
print <<EOF
<FORM METHOD="POST" ACTION="$script_path/cm.cgi?create">
Login: <INPUT TYPE="TEXT" NAME="login" SIZE="7" MAXLENGTH="7"><BR>
Pass: <INPUT TYPE="PASSWORD" NAME="pass" SIZE="7" MAXLENGTH="10"><BR>
Junk: <INPUT TYPE="Text" NAME="junk" SIZE="7" MAXLENGTH="10"><BR>
<INPUT TYPE="IMAGE" SRC="images/login.gif" WIDTH="75" HEIGTH="25" BORDER="0"><br>
</FORM><br>
$roster{$login}[$c_login]
$roster{$login}[$c_pass]
$roster{$login}[$c_junk]
EOF
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top