Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    682
    Thanks
    24
    Thanked 1 Time in 1 Post

    Code won't work in functions

    I was trying to use my own function to repeat the same code over & over without using it all in the page again but have a problem..

    Code works fine when not called via a function, but when I call the exact same code via the function, I have a problem..

    The problem is that when I refer to a SESSION variable it doesn't work.

    Any clue?

    Thanks!

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe post the code of that function ...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I find that sometimes I have to 'globalize' a variable declared outside of the function to use it inside.
    PHP Code:
    $count 0;
    function 
    inc_counter() {
     global 
    $count;
     
    $count++;

    I don't know much about sessions as I've never used them before, but perhaps it's something similar?

    Posting the relevant pieces of code would be helpful though..

    Sadiq.

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Posts
    682
    Thanks
    24
    Thanked 1 Time in 1 Post
    The code is really a bit to long to post (around 300 lines). I'll try & work with how I got it now.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •