CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
why isnt this printing to the file???

 



ultimategamer2k
User

Feb 3, 2001, 10:50 AM

Post #1 of 6 (738 views)
why isnt this printing to the file??? Can't Post

this script isnt opening/writing the inputed codes into the file!!! heres the code

-----------------------code------------------------------------
#!/usr/bin/perl
print "Conten-type: text/html\n\n";
use CGI qw(:standard);
print qq(<body bgcolor="#000000" text="#FFFFFF" link="#C0C0C0" vlink="#C0C0C0" alink="#FFFFFF">);

$action = param ('action');
$console = param ('console');
$gameName = param ('name');
$numberCodes = param ('NumCodes');
$user = param ('user');
$pass = param ('pass');
$user2 = param ('user2');
$pass2 = param ('pass2');
for ($count = 1; $count <= $numberCodes; $count++){
@description = param ('description$count');
}
for ($count = 1; $count <= $numberCodes; $count++){
@code = param ('code$count');
}


if (($user eq "whatever") && ($pass eq "whatever")) {


open(FILE, ">$console/$gameName.ug");
system("chmod 777 $console/$gameName.ug");
close FILE;

print <<beginningHTML;
<form method="POST" action="admin.cgi">
<div align="center" style="width: 620; height: 130">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="80%" bgcolor="#333333">
<tr>
<td width="100%">
<p align="center"><b><font size="1" face="Verdana">..::Adding Codes::..</font></b>
<div align="center">
<table border="2" cellpadding="0" cellspacing="0" width="95%" bgcolor="#060735" bordercolor="#000000">
<tr>
<td width="8%" bgcolor="#060735"> </td>
<tr>
<td width="8%" bgcolor="#A8A8A8"><b><font face="Verdana" size="1">Number</font></b></td>
<td width="42%" bgcolor="#A8A8A8"><b><font face="Verdana" size="1">Code Description</font></b></td>
<td width="50%" bgcolor="#A8A8A8"><b><font face="Verdana" size="1">Code</font></b></td></tr>
beginningHTML


for ($count = 1; $count <= $numberCodes; $count++){
print <<loopHTML;
<tr>
<td width='8%'><b><font face='Verdana' size='1'>$count</font></b></td>
<td width='42%'><b><font face='Verdana' size='1'><input type='text' name='description$count' size='20'></font></b></td>
<td width='50%'><b><font face='Verdana' size='1'><input type='text' name='code$count' size='20'></font></b></td>
loopHTML
}

print <<endHTML;
<tr>
<td width="8%"><b><font face="Verdana" size="1">User</font></b></td>
<td width="92%" colspan="2"><b><font face="Verdana" size="1"><input type="text" name="user2" size="20"></font></b></td>
<tr>
<td width="8%"><b><font face="Verdana" size="1">Pass</font></b></td>
<td width="92%" colspan="2"><b><font face="Verdana" size="1"><input type="password" name="pass2" size="20"></font></b></td>
<tr>
<td width="8%"><font face="Verdana" size="1"><b><input type="submit" value="Submit"></b></font></td>
<td width="92%" colspan="2"><font face="Verdana" size="1"><b><input type="reset" value="Reset"></b></font></td>
</table>
</div>
</form>
</center>
endHTML
if (($user2 eq "whatever") && ($pass2 eq "whatever")){
&file2;}
else{
print "something went wrong!!!!"; }
sub file2 {
open(FILE2, ">>$console/$gameName.ug") or die $!;
print FILE2 "$description:$codes\n";
close FILE2;
print "we now have codes for $gameName";
print "site updated";
}
}
--------------------/code----------------------------
any and all help would be apreciated
thanks!

visit my web site at http://ultimategamer.cjb.net


kencl
User

Feb 4, 2001, 1:08 AM

Post #2 of 6 (729 views)
Re: why isnt this printing to the file??? [In reply to] Can't Post

Your not actually saving the file, only opening and closing a filehandle. Add something like this:

Code
open(FILE, ">$console/$gameName.ug"); 
print FILE $whateverthedatafilevariablenameis;
system("chmod 777 $console/$gameName.ug");
close FILE;

It could also be that the server is not allowing you to set the permissions to group and world writable for security reasons.

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


ultimategamer2k
User

Feb 4, 2001, 9:15 AM

Post #3 of 6 (725 views)
Re: why isnt this printing to the file??? [In reply to] Can't Post

no, it makes the orriginal file whatever.ug, but when i try to open it again (it is chmodded) and print to it, it doesnt work

visit my web site at http://ultimategamer.cjb.net


Jasmine
Administrator / Moderator

Feb 4, 2001, 2:24 PM

Post #4 of 6 (722 views)
Re: why isnt this printing to the file??? [In reply to] Can't Post

What error are you receiving when it doesn't work? I didn't read through the entire code, but are you checking for errors with die?



ultimategamer2k
User

Feb 4, 2001, 4:29 PM

Post #5 of 6 (717 views)
Re: why isnt this printing to the file??? [In reply to] Can't Post

im not getting any errors, it thinks its working alright, but its not
damn thing

visit my web site at http://ultimategamer.cjb.net


Jasmine
Administrator / Moderator

Feb 4, 2001, 7:03 PM

Post #6 of 6 (713 views)
Re: why isnt this printing to the file??? [In reply to] Can't Post

It's obviously not working correctly, or you wouldn't have posted a problem Smile

Make your cgi error sub die, and put $! in your die message. This means that instead of the program saying "well, I couldn't do that, but let's keep going anyway", it'll say "whoa! that was important -- let me stop and let someone know that something crucial went wrong".

If you don't do that and post the error message, it'll be impossible to determine why the program isn't doing what it's supposed to be.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives