Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:55:44+00:00 2026-06-02T07:55:44+00:00

My php function does not recognize a variable defined in another php file that

  • 0

My php function does not recognize a variable defined in another php file that is included in within the same file. dbconnect.php makes a database connect. add_user.php has the add_user function which uses that database connection $dbco. I get an error message saying that $dbco is not defined for this function call: mysql_select_db("luxcal", $dbco); This must be something very obvious, but I don’t know what is happening.

dbconnect.php


<?php
    $dbco = mysql_connect("localhost","myuser","mypassword");
    if (!$dbco)
    {
        die('Could not connect: ' . mysql_error());
    }
?>

add_user.php


<?php include("dbconnect.php"); ?>

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

function add_user($username, $email, $password_text, $copasswd_text) {

    $password = md5($password_text);
    $copasswd = md5($password_text);
    $privPost = 1; // 3: max.
    $privSedit = 0;

    mysql_select_db("luxcal", $dbco);

    $q_add_user = "INSERT INTO users (`user_name`, `email`, `password`) VALUES ( '".mysql_real_escape_string($username)."', '".mysql_real_escape_string($email)."', '$password' )";
    $r_add_user = mysql_query($q_add_user);

    return;
}

echo add_user(trim($_REQUEST['uname']), trim($_REQUEST['uemail']), trim($_REQUEST['upass']), trim($_REQUEST['cpass']));

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:55:46+00:00Added an answer on June 2, 2026 at 7:55 am

    The variable $dbco is not available in the function add_user because it is not in the variable scope of the function.

    You can access it by adding global $dbco; inside the add_user function to make it available, or you can use $GLOBALS['dbco'] instead.

    Try:

    function add_user($username, $email, $password_text, $copasswd_text) {
        global $dbco;
        // rest of code...
    }
    

    Variables defined outside of functions are not available inside the function unless you pass them in or use global. Similarly, a variable defined in a function is not available outside the function (and is freed when the function returns).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a php function or class that does not require special libraries to
Is there any reasons why PHP's json_encode function does not escape all JSON control
Does anyone know of an available PHP function that takes a piece of text,
http://php.net/manual/en/function.trim.php The manual entry does say that I can remove any specified leading or
Thanks to this forum, I learnt PHP header function does not actually send header
The php function sprintf does not return the exact value; The sample code is
I am in need of a PHP function to check that a variable exist
I've this PHP function which does not work for negative numbers: function isOdd($num) {
I have problem that on server include() function does not want to work and
Is it possible to call a PHP function found in a file on another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.