home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

PHP functions

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2154
Discussions: 200,972, Posts: 2,379,760, Members: 246,336
Old June 3rd, 2004, 09:58 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Jun 2004
Posts: 8
PHP functions

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
Weeble is offline   Reply With Quote
Old 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.
vass0922 is offline   Reply With Quote
Old June 3rd, 2004, 10:59 AM     #3 (permalink)
Supporting our military
 
Bill in SD, CA's Avatar
 
Join Date: Oct 2002
Location: Bottom left of U.S.
Posts: 9,197
Might get some help here:

http://www.htmlforums.com/

Bill
Bill in SD, CA is offline   Reply With Quote
Old June 3rd, 2004, 11:10 AM     #4 (permalink)
Junior Member
 
Join Date: Jun 2004
Posts: 8
Cheers guys I got it sorted :P
Weeble is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to begin? Buzioid Webmastering and Programming 10 March 27th, 2004 11:19 AM
Tricky question - PHP form help dragonz Webmastering and Programming 7 February 10th, 2004 10:12 AM
Display mysql_query results LittleKing Webmastering and Programming 8 June 19th, 2003 12:52 AM
Best way to produce a pie-chart for web from data ? rh71 Webmastering and Programming 11 September 17th, 2002 12:41 AM
What would I use? CSS? BITM@D Webmastering and Programming 12 April 11th, 2002 06:52 AM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3050)
The disrespect of Obama by Russian .. (48)
Delete an OS (16)
Breaking: San Diego ACORN Document .. (10)
Nvidia GTX 260 problem (8)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
windows vista security holes (17)
Regular Build (11)
Internet Lost (5)
windows 7 problem (7)
Point and Shoot Camera Suggestions. (6)
Is the PSU I received dead? (15)
Recent Discussions
Delete an OS (16)
Multiple Restarts Required at Boot (4)
cell phone won't work (0)
Nvidia GTX 260 problem (8)
Is the PSU I received dead? (15)
Can't open Word (12)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (37)
Steam ID's, Gamertags etc... (4)
Games, Cables, PCI cards, and more fo.. (6)
Dept. of HS: NSA 'Helped' Develop Vis.. (17)
Linksys WMP54GS wireless card problem.. (5)
windows vista security holes (17)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)
help me pls laptop just stopped worki.. (0)
Open With ..... Win7 (3)
Laptop with wireless problem. (12)
Internet Lost (5)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Modern Warfare 2: Who Bought It? (65)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)


All times are GMT -4. The time now is 09:37 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28