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 9237335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:30:47+00:00 2026-06-18T07:30:47+00:00

I have recently started creating a website in PHP. Most of my code is

  • 0

I have recently started creating a website in PHP. Most of my code is working however I have found a problem that i am having trouble correcting.

I have a page where there are lots of calls to the database. at the top of my page I am connecting and using a SELECT to get some information on the related product.

At the bottom of the page I am connecting again getting comments on the related product.

My code is very lengthy so it is hard for me to show in here but the basics of this code are as follows:

PHP CODE
  SELECT's
  UPDATE's

HTML
  TABLE's
  IMAGE's
  ect...

PHP
  SELECT's

My code successfully runs all of my code when I first load up the page however when I click a button to update a table (in the top section of the code) the update is processed however the comments section at the bottom of the page brings back the following errer:

“no database selected.”

Both selects from the top of the page and the bottom of the page are connection to the same database and same table. Also the comments section that is bringing back the error works fine before I click the update button.

The code where my code says the error is happening is:

$commResult = mysql_query("SELECT u.id, u.USERNAME, c.COMMENT, c.DATE_ADDED, c.ACTIVE FROM USERS u, COMMENTS c WHERE c.box_id = $boxId ORDER BY c.DATE_ADDED DESC") or die (mysql_error());;

while ($row = mysql_fetch_array($commResult))
{
     //Do processing here.
}

My code for connection to the database. This is in a seperate file and i use a require_once(config.php); to call it at the top of every page that my code needs to connect to the database.

$username = "user";
$password = "password";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("databasename",$dbhandle) 
or die("Could not select databasename");
  • 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-18T07:30:48+00:00Added an answer on June 18, 2026 at 7:30 am

    I believe you may be opening a MySQL connection at the top of the script, closing it and reopening it without forgetting to select the database.

    If you’re using the old mysql_ functions (which you shouldn’t really be using for new code anymore, take a look at MySQLi and PDO) then you may have forgotten this line of code:

    mysql_select_db("databaseName");
    

    Or, if you’re using “raw queries”, you may be missing this line:

    mysql_query("USE databaseName");
    

    Although on the same script it’s probably not worth closing the database connection, it might be a better idea to keep it open throughout the script.

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

Sidebar

Related Questions

For school, I have recently started creating my own raytracer. However, I've hit a
I have a project that I have recently started working on seriously but had
Recently started working with pointers and have created a little script that is supposed
I have recently started working with Android. I don't have that much experience with
I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application
I have recently started using DocCheck for checking the validity of JavaDoc's in code
I have recently started to learn Objective-C and write my tests using OCUnit that
Recently I've started to write on asp.net mvc framework. I have a problem. I
I have recently started learning java for creating android apps. I have spent hours
I recently have started project in Joomla. I had to remove index.php from it

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.