is there something that says a variable doesn;t get passed when calling a sub in the same script? i am working on a web-based role-playing game and this is the script for inside the temple:
#!/usr/bin/perl ##############Modules############## use CGI qw/:standard/; use CGI::Carp "fatalsToBrowser"; use DBI; use CGI::Cookie; ##########Setup Variables########## %cookies = fetch CGI::Cookie; $id = $cookies{'id'}->value; $dbh = new CGI; $dbh=DBI->connect("DBI:mysql:database=flands;host=127.0.0.1;port=3306",edhunter,*****); die "Could not connect to database" if !$dbh; $sth = $dbh->prepare("SELECT money FROM chars WHERE id = '$id'"); if ($sth && $sth->execute()){ @results = $sth->fetchrow_array(); } my $money = $results[0]; my $action = param('action'); my $loc = param('loc'); my $goback = referer(); ###########Initiate############# if ($action eq "initiate"){ if ($loc eq "av"){ my $cost = 40; my $god = "Alvir and Valmir"; my $cash = $money - $cost; my $spec1 = ""; my $spec2 = ""; addgod(); } if ($loc eq "elnir"){ my $cost = 60; my $god = "Elnir"; my $cash = $money - $cost; my $spec1 = ""; my $spec2 = ""; addgod(); } if ($loc eq "sig"){ my $cost = 50; my $god = "Sig"; my $cash = $money - $cost; my $spec1 = "theivery"; my $spec2 = "1"; addgod(); } if ($loc eq "nagil"){ my $god = "Nagil"; my $spec1 = ""; my $spec2 = ""; nagili(); } if ($loc ne "av" && $loc ne "elnir" && $loc ne "sig" && $loc ne "nagil"){ print <<END_OF_HTML content-type: text/html <html> <head><title>The Fabled Lands - Lost in the Temple</title></head> <body bgcolor="#000000" text="#CCCCCC"><br><br>I'm sorry, but you seem to have become lost in the temple, please <a href="$goback">click here</a> to trace your way back. If you are sure you went the right way them please <a href="mailto:edhunter\@peanutbuttercheesecake.co.uk">email the authors'</a> or if you are managing the database yourself, please update your records.</body> <html> END_OF_HTML } sub nagili{ $dbh = new CGI; $dbh=DBI->connect("DBI:mysql:database=flands;host=127.0.0.1;port=3306",edhunter,*****); die "Could not connect to database" if !$dbh; $sth = $dbh->prepare("SELECT rank FROM chars WHERE id = '$id'"); if ($sth && $sth->execute()){ @results = $sth->fetchrow_array(); } my $rank = $results[0]; my $score = int(rand 6)+1; if ($score < $rank){ $winlose = "You have been accepted"; $dbh = new CGI; $dbh=DBI->connect("DBI:mysql:database=flands;host=127.0.0.1;port=3306",edhunter,*****); die "Could not connect to database" if !$dbh; $sth = $dbh->prepare("UPDATE chars SET god = 'Nagil' WHERE id = '$id'"); if ($sth && $sth->execute()){ }} else{ $winlose = "You have been rejected"; } print <<END_OF_HTML content-type: text/html <html> <head><title>The Fabled Lands - The Temple of $god</title></head> <body bgcolor="#000000" text="#CCCCCC"><br><br>It does not require payment to become an initiate of the Temple of Nagil. Instead you are made to endure many harsh test, the last of which being burried underground in a sealed casket. To represent these tests, you must use our Event Generation System (EGS), for information about using the EGS, please <a href="/flands/help/egs.html">click here</a>. This test represents rolling one dice and comparing with your current rank. If you score lower than your rank, you will be admitted, otherwise you must leave. To view the results of the test, select with your mouse under the dashed line below.<br><br>------------------------------<br><br><font color="#000000"><b>Your rank:</b> $rank<br><br><b>The Score:</b> $score<br><br><b>The Result:</b> $winlose</font><br><br><a href="$goback">Return to the Temple Foyer</a> </BODY></html> END_OF_HTML } sub addgod{ if ($money < $cost){ print <<END_OF_HTML content-type: text/html <html> <head><title>The Fabled Lands - The Temple of $god</title></head> <body bgcolor="#000000" text="#CCCCCC"><br><br>Sorry, but you seem to have unsuficcient funds to allow you to partake of the initiation ceremony. You must have at least $cost denarii to become an initiate, you only have $money.<br>You can come back any time to try again and we will be happy to accept you.<br><br><a href="$goback">Retrace your steps</a> </BODY></html> END_OF_HTML } else{ $dbh = new CGI; $dbh=DBI->connect("DBI:mysql:database=flands;host=127.0.0.1;port=3306",edhunter,*****); die "Could not connect to database" if !$dbh; $sth = $dbh->prepare("UPDATE chars SET god = '$god' WHERE id = '$id'"); if ($sth && $sth->execute()){ } $dbh = new CGI; $dbh=DBI->connect("DBI:mysql:database=flands;host=127.0.0.1;port=3306",edhunter,*****); die "Could not connect to database" if !$dbh; $sth = $dbh->prepare("UPDATE chars SET money = '$cash' WHERE id = '$id'"); if ($sth && $sth->execute()){ } if ($spec1 ne ""){ $dbh = new CGI; $dbh=DBI->connect("DBI:mysql:database=flands;host=127.0.0.1;port=3306",edhunter,*****); die "Could not connect to database" if !$dbh; $sth = $dbh->prepare("UPDATE chars SET $spec1 = $spec1 + $spec2 WHERE id = '$id'"); if ($sth && $sth->execute()){ }} print <<END_OF_HTML content-type: text/html <html> <head><title>The Fabled Lands - The Temple of $god</title></head> <body bgcolor="#000000" text="#CCCCCC"><br><br>Thank you for becoming an initiate of the Temple of $god, Your donation is gratefully accepted. You should now see $god on your stats sheet.<br><br><a href="$goback">Retrace your steps</a> </BODY></html> END_OF_HTML }}} ---------------------------------------------------------------------------------------------------------- i know it is ulgy, but i am quite new to perl. why when the dynamic html page are generated does it show the $god and $winlose variabled as being empty? i know the database part works, but without the $god variable it will always add a null value to the database. any ideas? -- Matthew Harrison Internet/Network Services Administrator Peanut-Butter Cheesecake Hosting Services Genstate www.peanutbuttercheesecake.co.uk -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]