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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:32:53+00:00 2026-06-04T06:32:53+00:00

I am trying to learn php and mysql. So i tried making a database

  • 0

I am trying to learn php and mysql. So i tried making a database using phpmyadmin and connect it with my php.
Here is a simple example where I try to see if the database is working

<?php
$connection = mysql_connect("localhost","root");
if(!$connection) {
    die("Database connection failed: " . mysql_error());
    $db_select = mysql_select_db("nameofdatabase",$connection);
    if (!$db_select) {
        die("Database selection failed:: " . mysql_error());
        }
    }
?>
<html>
<head>
<title>Databases</title>
</head>
<body>
<?php
$result = mysql_query("SELECT * FROM nameofdatabasetable", $connection);
if (!$result) {
    die("Database query failed::: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
echo $row[1];
}

?>

</body>
  </html>
<?php
mysql_close($connection);
?>

and i get

 Database query failed::: No database selected

which means than this part of code

<?php
$result = mysql_query("SELECT * FROM users", $connection);
if (!$result) {
    die("Database query failed::: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
echo $row[1];
}

?>

is not working (i put a different number of these “:” in each if.
Any help would be appreciated! Thank you!

  • 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-04T06:32:54+00:00Added an answer on June 4, 2026 at 6:32 am

    The logic for your code doesn’t make sense because if the connection doesn’t happen then you would not be able to select a database and your database select statement is within the logic for if you cannot connect to the database. Try this instead:

    $connection = mysql_connect("localhost","root"); 
    if(!$connection) { 
       die("Database connection failed: " . mysql_error()); 
    }else{
       $db_select = mysql_select_db("nameofdatabase",$connection); 
       if (!$db_select) { 
           die("Database selection failed:: " . mysql_error()); 
       } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to learn php/mysql. inserting data into mysql works fine but inserting those
I am trying to learn how to create tags in PHP/MySQL. Does anyone know
I am new to PHP and trying to learn it by creating a database
I have limited knowledge of php and mysql, I am trying to learn it
I'm using HostMonster as my web host and I'm trying connect to a database
trying to get my first little PHP script to connect to a local mySql
Im trying to learn php by doing a little project using apache server. I
So im here trying to learn more php and... trying to add an image
Hey everyone. While I'm trying to learn some PHP and mySQL, I ran into
I'm trying to learn oop. I'm working with PHP-MySQL. And I have troubles about

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.