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

help please 1

Status
Not open for further replies.

PhoenixDown

Programmer
Joined
Jul 2, 2001
Messages
279
Location
CA
I'm using this code to number the guesbook entries in my database file:

Code:
open (TOTALENTRIES, "$vars_gen{'CGIPath'}/variables/vars_entries.cgi");
@line = <TOTALENTRIES>;
close (TOTALENTRIES);
@Backwards = reverse(@line);
$LastLine = @Backwards[0];
@LastStats = split(/\|/, $LastLine);
$LastNumber = $var1;
chomp($LastNumber);
$NextNumber = $LastNumber + 1;
} else {
$NextNumber = 1;
}

But I get an ISE with that and I don't know what's wrong.

If you need to know, I use the following to call the guestbook content:

Code:
open(DATA,&quot;<$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die (&quot;Unable to open guestbook entry file.&quot;);
@line = <DATA>;
close(DATA);
foreach $line (@line) {
 $line =~ s/\n//g;
 ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12,$var13,$var14,$var15,$var16,$var17) = split(/\|/,$line);

Please fix it. :-) - Go there!
 
I edited it a bit to:

Code:
open (TOTALENTRIES, &quot;$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;);
@line = <TOTALENTRIES>;
close (TOTALENTRIES);
@Backwards = reverse(@line);
$LastLine = $Backwards[0];
@file = split(/\|/, $LastLine);
$LastNumber = $var1;
chomp($LastNumber);
$NextNumber = $LastNumber + 1;
} else {
$NextNumber = 1;
}

and my server error log says there's an error near { else, but it looks okay... - Go there!
 
Well thats your problem, where is the if(){} statement? In order to have an else{}, you have to have an if, unless there is some code you are not including, it is the lack of the if statement.

Hope this helps.
-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Allright I added the if statement:

Code:
if (-e &quot;$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) {
open (TOTALENTRIES, &quot;$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;);
@line = <TOTALENTRIES>;
close (TOTALENTRIES);
@Backwards = reverse(@line);
$LastLine = $Backwards[0];
@line = split(/\|/, $LastLine);
$LastNumber = $var1;
chomp($LastNumber);
$NextNumber = $LastNumber + 1;
} else {
$NextNumber = 1;
}

What you told me to fix stopped the error. The script only prints 1, it doesn't go to 2...3...4, ect.

Here is the file writing part:

Code:
open (FILE, &quot;>>$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;) or die(&quot;Unable to open vars_entries.cgi file for writing.&quot;);
flock(FILE,LOCK_EX);
print FILE qq!$NextNumber|$in{'Field1'}|$in{'Field2'}|$in{'Field3'}|$in{'AvatarURL'}|$in{'ICQField'}|$in{'AIMField'}|$in{'MSNField'}|$in{'YahooField'}|$in{'CusField1'}|$in{'CusField2'}|$in{'CusField3'}|$in{'CusField4'}|$in{'Field4'}|$Date|$Time|$IP|$Host\n!;
flock(FILE,LOCK_UN);
close (FILE);
chmod(0777, &quot;$vars_gen{'CGIPath'}/variables/vars_entries.cgi&quot;);

My database file looks like:

Code:
1|Calvin|<A HREF=&quot;mailto:calvin@puremadnezz.com&quot;>|<A HREF=&quot;[URL unfurl="true"]http://www.puremadnezz.com/&quot;>||||||||||Testing|06-21-2001|17:14:22|216.130.72.133|c-72-133-res1.mts.net[/URL]
1|Calvin|<A HREF=&quot;mailto:calvin@puremadnezz.com&quot;>|<A HREF=&quot;[URL unfurl="true"]http://www.puremadnezz.com/&quot;>||||||||||Testing[/URL] again!  <IMG SRC=&quot;[URL unfurl="true"]http://www.puremadnezz.com/gb/smilies/smile.gif&quot;>|06-21-2001|17:15:12|216.130.72.133|c-72-133-res1.mts.net[/URL]

Please help me! Thank you. - Go there!
 
The script won't print anything more than 1, whether or not the file exists.

If you want the counter to advance, then you have to wrap that chunk of code in a loop. If you do that, it should work fine.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top