Jump to content

[SOLVED] Undefined variable with require_once


isaac_cm

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.