SitePoint Sponsor |
|
User Tag List
Results 1 to 15 of 15
Thread: php functions
-
Sep 23, 2000, 14:47 #1
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi everyone,
i'm experimenting with a simple php script, and here's what it looks like:
if ($var1 == "222") {
write();
}
else {
echo("Error");
}
fuction write()
echo("this is a test");
but the function write() doesn't execute when i call the write(); , and i get an error from my server.
i'm pretty new to php so would somebody please help me out on how to call a function up.
Thank you
Sang N
sang@vinasite.com
-
Sep 23, 2000, 15:02 #2
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Try replacing your write() function with the following:
Code:function write() { echo("this is a test"); }
[Edited by kyank on 09-23-2000 at 04:23 PM]Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 23, 2000, 15:09 #3
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi,
the error i get is:
"Fatal error: Call to unsupported or undefined function write() in /home/vina/vinasite-www/validate.php on line 24
"
and on line 24, i have:
write();
Sang N.
sang@vinasite.com
-
Sep 23, 2000, 15:24 #4
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You have misspelled "function" as "fuction".
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 23, 2000, 15:26 #5
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that's corrected, but i still get the same error...
-
Sep 23, 2000, 15:30 #6
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
The following code works perfectly here:
Code:<? $var1="222"; if ($var1 == "222") { write(); } else { echo("Error"); } function write() { echo("this is a test"); } ?>
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 23, 2000, 15:49 #7
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
humm...
weird..
I guess it's a problem with my server's configuration.
Thanks for your help
-
Sep 23, 2000, 18:50 #8
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It is possible that you may need to define your function above the call to it.
So this should work:
<?
function write() {
echo("this is a test");
}
$var1="222";
if ($var1 == "222") {
write();
}
else {
echo("Error");
}
?>
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Sep 23, 2000, 18:53 #9
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks
that worked!
-
Sep 23, 2000, 18:58 #10
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No problem! If you were working in a class, you could call it from wherever using $this->functionname() but since it was stand alone you would have to define it before you could call it.
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Sep 23, 2000, 19:00 #11
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Odd. That was not required here (witness my code above). What version of PHP are you running?
Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 23, 2000, 19:03 #12
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
4.0.2 and I have run into that situation several times, as the page is parsed by the server it goes on down the page and tries to run write() before it know s what it is. Not sure why it worked for you
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Sep 23, 2000, 19:10 #13
- Join Date
- Apr 2000
- Location
- Melbourne, Australia
- Posts
- 2,571
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
4.0.1pl2 here... My test file contained only the code in my post above, and worked withtout a hitch. To satisfy my curiosity, would you care to try it on your own server?
From p.132 of "Professional PHP Programming" by WROX Press:
In PHP3, the function declaration must appear in the code before any invocations of the function. However, in PHP4 the function can be called prior to its declaration.Kevin Yank
CTO, sitepoint.com
I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
Baby’s got back—a hard back, that is: The Ultimate CSS Reference
-
Sep 23, 2000, 20:57 #14
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Don't you know "Curiosity killed the Cat!" No, just kidding it worked on my machine, so I don't know what happened with his machine?
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Sep 23, 2000, 20:57 #15
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe he was runnning PHP3
Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks