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

  • Home
  • SEARCH
  • 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 6718607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:59:25+00:00 2026-05-26T08:59:25+00:00

//require_once(../StoredProcedure/connect.php); $conn=mysql_connect(localhost,root,) or die(mysql_error); mysql_select_db(politicalforum,$conn); function updateThread($threadID, $content) { mysql_query(UPDATE threads SET content=’$content’ WHERE

  • 0
     //require_once("../StoredProcedure/connect.php");
  $conn=mysql_connect("localhost","root","") or die(mysql_error);
  mysql_select_db("politicalforum",$conn); 

 function updateThread($threadID, $content) 
 {
     mysql_query("UPDATE threads
                  SET content='$content'  
                  WHERE thread_id=$threadID") ;
    // $res = mysql_query($sql) or trigger_error(mysql_error().$sql);
     mysql_close();
 }

I get this each time..what am I doing wrong?

No database selected.

I am calling that function from an outside file…like this..

if(isset($_GET['threadID']) && isset($_POST["reply"]) && isset($_POST['textareas']))
   {

        updateThread($_GET['threadID'], $_POST['textareas']); 

       $postValid=TRUE;
   }
  • 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-05-26T08:59:26+00:00Added an answer on May 26, 2026 at 8:59 am

    Your connection is likely going out of scope, causing the mysql_query to run against the context’s database object which doesn’t exist by the time updateThread fires.

    In this case you need to pass the connection into the mysql_query function inside updateThread. Architecturally there are two ways you can go about this:

    1) Open and close the connection inside your updateThread function:

    function updateThread($threadID, $content) 
    {
       $conn=mysql_connect("localhost","root","") or die(mysql_error);
       mysql_select_db("politicalforum",$conn); 
       mysql_query("UPDATE threads
                    SET content='$content'  
                    WHERE thread_id=$threadID", $conn) ;
       mysql_close($conn);
       $conn = null;
    }
    

    2) Pass the connection as a variable to updateThread, in case you want to use the same connection in other functions. PHP will automatically close and dispose your MySQL connection when the script finishes:

    function updateThread($threadID, $content, $conn) 
    {
       mysql_query("UPDATE threads
                    SET content='$content'  
                    WHERE thread_id=$threadID", $conn) ;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the following example appropriate for PHP's require_once construct? function foo( $param ) {
When working on a file, I open and close connections like this: require(../StoredProcedure/connect.php);//users.user_id //..some
require_once('phpmailer/class.phpmailer.php'); function smtpmailer($to,$from,$subject,$body) { define('GUSER', 'xxx'); // Gmail username define('GPWD', 'xxx'); // Gmail password
I have a section of code like the following: ---- file.php ---- require_once(mylib.php); function($a,$b)
require_once('classes/class.validation.php'); $array = $_POST['array']; $pass_profanity = false; $validation = new Validation; function check_for_profanity($input){ if(is_array($input)){
How do I use the require_once php function in Codeigniter on a normal PHP
PHP manual suggests to autoload classes like function __autoload($class_name){ require_once(some_dir/.$class_name..php); } and this approach
--- A.php ---- require_once 'B.php'; class A { public function __constructor($x){...} public function foo()
Here is my PHP code: function SendCookieToTheMail() { require_once 'swift-mailer/lib/swift_required.php'; //Create the Transport $transport
class_1.php class class_1 { public function __construct() { require_once $_SERVER['DOCUMENT_ROOT'].'/array.php'; } } class_2.php class

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.