/    Sign up×
Community /Pin to ProfileBookmark

Trouble passing a variable through to a function?

[code=php]<?php

$page = new page();
$page->random_banner(‘Connections/dbConn.php’);
$page->Display_Section_One();
?>[/code]

[code=php]<?
function random_banner($path= ”)
{

require($path);
$id = rand(1,11);
mysql_select_db($database_dbConn, $dbConn);
$query = “SELECT banner_id, image, url, alt, short_comment, long_comment, author, company
FROM rss_banner
WHERE banner_id = $id”;
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$totalRows = mysql_num_rows($result);
return $row;
?>[/code]

Im trying to pass a string variable which is the location of the database connection from a page into the random_banner function. I then want to pass this through to the require() function however is comes up with an error. The string vlaue is passed through as if i do an echo of $path it produces the string value however the require() function wont recognise it. Any ideas?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@martinsandhuauthorSep 24.2005 — any ideas?
Copy linkTweet thisAlerts:
@NogDogSep 24.2005 — Try passing the full, absolute path name instead of a realtive one (for example: "/home/yourname/public_html/includes/Connections/dbConn.php" for UNIX/Linux, or "c:/php/includes/Connections/dbConn.php" if Windows).
Copy linkTweet thisAlerts:
@martinsandhuauthorSep 25.2005 — its on a server and i have passed it the full path it seems to timout and wont connect to the database the error i get is:

PHP Warning: page::random_banner(http://www.rocketss.com/Connections/dbConn.php) [function.random-banner]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:InetpubwwwrootRocketclassespage.php on line 60 PHP Fatal error: page::random_banner() [function.require]: Failed opening required 'http://www.rocketss.com/Connections/dbConn.php' (include_path='.;C:php5pear') in C:InetpubwwwrootRocketclassespage.php on line 60

any ideas?
Copy linkTweet thisAlerts:
@SheldonSep 25.2005 — dont use the domain, use ther server path as Charles said,
(for example: "/home/yourname/public_html/includes/Connections/dbConn.php" for UNIX/Linux, or "c:/php/includes/Connections/dbConn.php" if Windows).[/quote]
Copy linkTweet thisAlerts:
@SheldonSep 25.2005 — There your path is in the error!
<i>
</i>C:InetpubwwwrootRocketConnectionsdbConn.php
×

Success!

Help @martinsandhu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...