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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:16:11+00:00 2026-05-28T04:16:11+00:00

I am trying to connect to a mysql database within a php script. So

  • 0

I am trying to connect to a mysql database within a php script. So far, my code looks like

//to my knowledge, this works. I was able to echo out the correct name
$name = $_POST["name"];


$server_name = "localhost"; 
$user_name = //my user name
$password = //my password
$db_name = //the db name

//it passes this error check, so I am connecting properly I am assuming 
$dbconn = mysql_connect($server_name, $user_name, $password) 
    or die ('Could not connect to database: ' . mysql_error());

mysql_select_db($db_name, $dbconn);

$query = "SELECT * 
          FROM brothers 
          WHERE name = '$name'";

//it DOES NOT make it past this one
$result = mysql_query($query)
    or die('Bad Query: ' . mysql_error());

//filter through the query as a row
$row = mysql_fetch_array($result, MYSQL_ASSOC);

//echo the result back to the user
echo $row["name"];
echo $row["major"];


//close the connection 
mysql_close($dbconn);

I keep getting the error “No Database Selected”, even though I am sure that I spelled the database name correctly (I copy pasted). Does anyone know why my code might be throwing this error?

  • 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-28T04:16:12+00:00Added an answer on May 28, 2026 at 4:16 am

    Could be a permissions issue(the user which logon maybe don’t have read rights on the database) :

    mysql_select_db() fails unless the connected user can be authenticated
    as having permission to use the database.

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

Sidebar

Related Questions

I am trying to connect to mysql database in a PHP script run via
I am trying to connect to mysql database from jsp page. The connection code
I'm trying to connect to MySQL database from node.js using db-mysql library. Everything works
im getting this error while trying to connect a mysql database to an editor,
trying to get my first little PHP script to connect to a local mySql
My php code fails to connect to the mysql database on my web server.
I am trying to connect to a remote MySQL database via PHP that is
Hey guys im trying to connect to my remote mysql database and my code
I am trying connect to MySQL database from ASP.net code. some my connection is
I'm trying to connect to a hosted MySQL database from my Ruby script. require

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.