Hello Freinds,

Does any one know that can I access the the variables , registered using session_variable, from whithin the user defined fuction.

  1. I'm passing the session register variable to the form.
  2. I'm calling local user defined function in this form.
  3. I need to use the session_varialbe in this function, in order to execute the query.
  4. When executed the query from the User Defined function, it doesn't have value refered by session_variable.

In simple words, I'm not able to access the session variables from within the User Defined function.

If any one know, could you pls. reply.

Bharti.

    Well, maybe you could give some part of your code, because i don't see how you do it... Which way do you use to pass the session_register variable to the form ? Which version of php do you use ?

      Hello, Thanks for you reply. Following code is in login.php

      session_start();
      session_register('sess_name');
      session_register('sess_prog');
      session_register('sess_part');

      $sess_name = $name;
      $sess_prog = $prog;
      $'sess_part'= $'sess_part';

      I'm calling a form bsc.php from this login.php :


      // bsc.php : following is the excert of the bsc.php coding.

      <?php
      session_start();

      print($sess_name);
      print($sess_prog);
      print($sess_part); // these does print the correct value for me.

      ..... few more code over here......

      // user defined funciton

      function bld_tbl($tblName, $semVal, $chbName){

      print($sess_prog);

      print($sess_part);

      print("at function start");

      $modStmt = "select mod_id, title, mod_wt from modid_titles_2002_2003 where prog = \"$sess_prog\" and part = \"$sess_part\" and semester = \"$semVal\" ";
      print($modStmt);

      ..... few more coding here .....

      }

      The problem is, when printed or used the session variables in funciton, it doesn't have any value in it !!!, though it does have the correct value out side the function.

      ?>

        Without seeing some code it's a bit difficult to give a comprehensive and specific answer. But based on what has been said, a pretty-much guaranteed solution would be to throw out registering session variables entirely.

        That is, don't bother with session_register('varname'); and instead use $_SESSION['varname'] wherever you now use $varname.

          You have to make them global within the function like that:

          <?php 
          session_start(); 
          
          print($sess_name); 
          print($sess_prog); 
          print($sess_part); // these does print the correct value for me. 
          
          ..... few more code over here...... 
          
          // user defined funciton 
          
          function bld_tbl($tblName, $semVal, $chbName){ 
          
          global $sess_prog;
          global $sess_part;
          
          print($sess_prog); 
          
          print($sess_part); 
          
          print("at function start"); 
          
          $modStmt = "select mod_id, title, mod_wt from modid_titles_2002_2003 where prog = \"$sess_prog\" and part = \"$sess_part\" and semester = \"$semVal\" "; 
          print($modStmt); 
          
          ..... few more coding here ..... 
          
          } 
          
          

          or you have to access global variable $_SESSION like this

          print($_SESSION["sess_prog"]); 
          print($_SESSION["sess_part"]);
          

          Zdenek

            Thanks to both friends, who suggested to use _SESSION['var name'] instead of $var_name... It works perfect....

            I have come accross another related problem..... that is... the user defined function is not able to access any other variables within the form.... is that right ? ....

            I need to refer other local variables of the form as well.... How do I do that? Can you please advise. Thanks.

              Even by making them global as I mentioned in first posibility or you have to pass them as an parameter.

              Zdenek

                Hello dear friend,

                I'm very much thankful to you....

                Yes, I can access those local variables in from by refering them as global $varname in the user defined function.....

                Thanks a lot... I can proceed to my project work now, which I was stucked for long.

                  this problem is solved by receiving the advice from forum friend.... Thanks to every one...

                    Write a Reply...