Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

included file isn't really being included...

Status
Not open for further replies.

Thomas001

Programmer
Jun 24, 2004
29
US
my include file
Code:
//
// [CONNECT!]
global $db_host, $db_user, $db_pass, $db_use, $db_table, $linkID;

function Connect()
{
	//if (!isset($db_host)) // If not set use defaults
	$db_host=('localhost');
	
	//if (!isset($db_user)) // If not set use defaults
	$db_user=('root');
	
	//if (!isset($db_pass)) // If not set use defaults
	$db_pass=('');
	
	//if (!isset($db_use)) // If not set use defaults
	$db_use=('Login');
	
	//if (!isset($db_table)) // If not set use defaults
	$db_table=('logins');

	// Database
	$linkID = mysql_connect($db_host, $db_user, $db_pass);
	mysql_select_db($db_use, $linkID);
} 
//
//



other file
Code:
include 'INCLUDE/uber_dbconnect.php';

function Verify()
{
$auth = false;

	Connect();
	$result = mysql_query(" SELECT pass FROM $db_table WHERE acc = '$sent_acc' ", $linkID);
	$pass = mysql_fetch_row($result);
	mysql_close($linkID);


  if ( ($pass[0]) === ($sent_pass) )
  {
  $auth = true;
  }
    return $auth;
}



Its not retrieving anything I put in the included file.... I've been looking at it for 45min now and can't see why.
 
Observation:
In order to make variables inside a function taken from the global scope the global statement ought to be inside the function declaration. Otherwise vars inside the function are of local scope.
 
Code:
//
// [CONNECT!]
global $db_host, $db_user, $db_pass, $db_use, $db_table, $linkID;


function Connect($db_host, $db_user, $db_pass, $db_use, $db_table, $linkID)
{
	//if (!isset($db_host)) // If not set use defaults
	$db_host=('localhost');
	
	//if (!isset($db_user)) // If not set use defaults
	$db_user=('root');
	
	//if (!isset($db_pass)) // If not set use defaults
	$db_pass=('');
	
	//if (!isset($db_use)) // If not set use defaults
	$db_use=('Login');
	
	//if (!isset($db_table)) // If not set use defaults
	$db_table=('logins');

	// Database
	$linkID = mysql_connect($db_host, $db_user, $db_pass);
	mysql_select_db($db_use, $linkID);
	
	global $db_host, $db_user, $db_pass, $db_use, $db_table, $linkID;
} 
//
//



I still get the same errors
[QUOTE]
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/[URL unfurl="true"]www/html/Login/check.php[/URL] on line 22

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /var/[URL unfurl="true"]www/html/Login/check.php[/URL] on line 23

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /var/[URL unfurl="true"]www/html/Login/check.php[/URL] on line 24
Info: 
[/QUOTE]

I have a print function directly after the call to Connect() and it brings back none of those variables
 
That would be because according to the code you just posted, you're still invoking the global directive outside of your function definition.

This:
Code:
global $db_host, $db_user, $db_pass, $db_use, $db_table, $linkID;


function Connect($db_host, $db_user, $db_pass, $db_use, $db_table, $linkID)
{

Will likely not work.

This:

Code:
function Connect($db_host, $db_user, $db_pass, $db_use, $db_table, $linkID)
{
   global $db_host, $db_user, $db_pass, $db_use, $db_table, $linkID;

has a much better shot of working.


See Variable scope in the PHP online manual.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Suggestions:
Add error checking to the mysql statements
Code:
# ex. 1
$linkID = mysql_connect($db_host, $db_user, $db_pass) [COLOR=red]OR die('Connect error: '.mysql_error())[/color];
# ex. 2
$result = mysql_query(" SELECT pass FROM $db_table WHERE acc = '$sent_acc' ", $linkID) [COLOR=red]OR die('Query error: '.mysql_error())[/color];
 
ok, I understand..

the function needs to directly see the functions (excuse my lack of correct terminology)

function example($blah1 $blah2)
{
oi
}
 
I don't understand the meaning of "the function needs to directly see the functions" well enough to comment whether you're on the right track or not.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top