PHP functions  | |
June 3rd, 2004, 09:58 AM
|
#1 (permalink)
| | Junior Member
Join Date: Jun 2004
Posts: 8
|
Ok, in my mind this should work but it returns an error (displayed bottom) for some unknown reason, anyone have any comments? Code: <?php
$yes = $_POST['yes']; $no = $_POST['no'];
$yesnum = "yes.txt";
$nonum = "no.txt";
if($_POST==$yes){
function displayYes($yesnum) {
$fpy = fopen($yesnum,rw);
$ynum = fgets($fpy,9999);
fclose($fpy);
$fpy = fopen($yesnum,w);
$ynum += 1;
print "$ynum say yes";
fputs($fpy, $ynum);
fclose($fpy);
}
} else {
function displayNo($nonum) {
$fpn = fopen($nonum,rw);
$nnum = fgets($fpn,9999);
fclose($fpn);
$fpn = fopen($nonum,w);
$nnum += 1;
print "$nnum say no";
fputs($fpn, $nnum);
fclose($fpn);
}
}
//Display the Current Hits
displayYes($yesnum);
displayNo($nonum);
?> And here is the error: Code: Fatal error: Call to undefined function: displayyes() in /home/weeble/public_html/azzer/smell.php on line 32 |
| |
June 3rd, 2004, 10:40 AM
|
#2 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,397
|
Granted I'm not a PHP developer, but I've never seen a language where you define a function within a conditional.
Usually you'll define the function off to the side, then you'll call the function within the conditional. Code: <?php
$yes = $_POST['yes']; $no = $_POST['no'];
$yesnum = "yes.txt";
$nonum = "no.txt";
if($_POST==$yes){
displayYes($yesnum);
} else {
displayNo($nonum);
}
//Display the Current Hits
function displayYes($yesnum) {
$fpy = fopen($yesnum,rw);
$ynum = fgets($fpy,9999);
fclose($fpy);
$fpy = fopen($yesnum,w);
$ynum += 1;
print "$ynum say yes";
fputs($fpy, $ynum);
fclose($fpy);
}
function displayNo($nonum) {
$fpn = fopen($nonum,rw);
$nnum = fgets($fpn,9999);
fclose($fpn);
$fpn = fopen($nonum,w);
$nnum += 1;
print "$nnum say no";
fputs($fpn, $nnum);
fclose($fpn);
}
?>
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
|
| |
June 3rd, 2004, 10:59 AM
|
#3 (permalink)
| | Supporting our military
Join Date: Oct 2002 Location: Bottom left of U.S.
Posts: 9,197
| |
| |
June 3rd, 2004, 11:10 AM
|
#4 (permalink)
| | Junior Member
Join Date: Jun 2004
Posts: 8
|
Cheers guys  I got it sorted :P |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |