problems with functions/included files/mysql resource

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Everyone, I am new to this or any news group.

The end of this story is that I believe I am calling a function from within 
a function in a way that I should not be, but I cannot figure out exactly 
what part I am doing incorrectly.

I have the following main file with other content included from outside 
files (summarized):
<?php  //main_file.php

    //the following defines functions to connect to the data base and submit 
queries
    require('databasefunctions.php');

     / /the following defines a function that uses above database functions 
to build a dropdown list from database tables
    require('dropdownlistfunctions.php');


    //some if/then statements
    //...
    //...

    //the following builds a form that is displayed. It uses a function from 
dropdownlistfunctions.php (above) to build a dropdown list.
    require('build_form.php');
?>

When I use the functions from databasefunctions.php directly in the 
main_file.php to connect to a database and run a query, the functions work 
successfully. However, when I use those functions from within a function 
defined inside the dropdownlistfunctions.php, I get an error "Undefined 
variable: [variable name]". The [variable name] is supposed to contain the 
mysql-link resource. Since it isn't there, I also get additional warnings 
that the mysql_query didn't receive a valid mysql-link resource.

In the function to connect to and select the database, I make the mysql-link 
resource a global value.

Inside the dropdownlistfunctions.php, when I simply write the statements 
directly in the function to connect to and select the database, and run the 
query, that works too.

Is there a basic rule about including/requiring files, and using functions 
within functions that I am not abiding by? It feels as though I am just 
trying to do some particular thing that you can't do when working with 
functions that use other functions ... and maybe to do with 
including/requiring files as well.

Any wisdom would be eagerly and gratefully consumed.

Kindest regards, JH























-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux