Jump to content

include files question


jasman

Recommended Posts

I am trying to write a function in a file that will lookup a value in mysql and return it.  I want to put this function into a php file to be included in another page.  On the main page, I would use a query like this and it works fine:

mysql_select_db($database_workorder, $workorder);
$query_rst_org2 = "select org_name from org where org_id = $orgid";
$rst_org2 = mysql_query($query_rst_org2, $workorder) or die(mysql_error());
$row_rst_org2 = mysql_fetch_assoc($rst_org2);
$totalRows_rst_org2 = mysql_num_rows($rst_org2);

When I try this in the included file it fails with this error:
mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/u4//html/lookup2.php on line 34

line 34 is this line: mysql_select_db($database_workorder, $workorder);

doesn't the include function basically paste the code into the calling page?  and if so shouldnt all of the vars that are available in the calling page be available to the code that is being called in the include page?

obviously my approach is flawed, can someone please explain?
thanks
Jason



Link to comment
Share on other sites

As far as I understand is that each page still needs its own conection. What I'm doing is I wrote a conection.php with just the server username and password in and am including it to all my pages.
For the including page that has to do something will have to have a conection. Its working as a combined page but still are a stand alone and have to know where the database are.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.