isaac_cm Posted July 28, 2007 Share Posted July 28, 2007 Hello, I get the following notice whenever I try to call a function from my file : Notice: Undefined variable: database_mainsqldb in F:\mysite\Site Template\includes\myfunc.php on line 7 this variable "$database_mainsqldb" is defined in this file "../Connections/mainsqldb.php" and I include this file like that: <?php require_once('../Connections/mainsqldb.php'); ?> I tried to use the same function in the same calling page and it work fine without the previous notice!! the error appear only when I try to call it from myfunc.php here is the script of myfunc.php function delete_attr($aid){ mysql_select_db($database_mainsqldb, $mainsqldb); $deleteSQL = "DELETE FROM table1 WHERE at_id=" . $aid; $Result1 = mysql_query($deleteSQL, $mainsqldb) or die(mysql_error()); } plz advice thanks Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 28, 2007 Share Posted July 28, 2007 I suggest you loop up variable scope and functions. To start with, try reading through this section from a free online php book: http://hudzilla.org/phpwiki/index.php?title=Variable_scope_in_functions Basically, variables declared outside of a function aren't available inside a function unless you pass them into it as a parameter, or use the global keyword. Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted July 28, 2007 Author Share Posted July 28, 2007 I see now, but what you suggest, I dont want to make global variables for security reasons I do not want also to place those functions in mainsqldb.php. any other solutions ? thanks Quote Link to comment Share on other sites More sharing options...
isaac_cm Posted July 29, 2007 Author Share Posted July 29, 2007 never mind I will pass the variables as an arguments Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.