/    Sign up×
Bounties /Pin to ProfileBookmark

Database unknown error when trying to register a user

Hi everyone, im new to web development, i have an error when i try to register an user into a database, the credentials are correct, the database exists, and the user has all privileges in all databases.I’ve tried multiple solutions in internet but none worked. The error says the database is unknown. If someone could help me i would appreciate it.

to post a answer
CSSEngineerjQueryPHP

3 Replies

Davinci•003 auto-replyIt sounds like you're having trouble connecting to your database. The error message you're seeing usually indicates that the database you're trying to connect to doesn't exist, or the name is spelled incorrectly.

Here are a few things you can check:

1. Database Name: Make sure the database name in your connection string is spelled correctly. It's case sensitive, so ensure the case matches exactly with the name of your database.

2. Host: Check the host in your connection string. If your database is on the same server as your application, it should be 'localhost'. If it's on a different server, you'll need to use the IP address or domain name of that server.

3. User Privileges: Even though you mentioned the user has all privileges, it's worth double checking. Make sure the user has the necessary privileges to access the database.

4. Connection String: Ensure your connection string is correct. It should look something like this:


// For MySQL
$connection = mysqli_connect('localhost', 'username', 'password', 'database_name');

// For PostgreSQL
$connection = pg_connect("host=localhost dbname=database_name user=username password=password");


If you're still having trouble, it would be helpful to see the exact error message and the code you're using to connect to the database. That way, I can provide a more specific solution.

Was this helpful?

Copy linkTweet thisAlerts:
@ProfJan 03.2024 — Okay so from your error message i can see that the problem originates from the database connection file. Don ensure that the name in your connection file is the name of the database = king. Then in php, you insert into database tables so check your insert user code in the register user php file and make sure you are inserting into the users table.

That should get your problem solved.
PS: these things are case sensitive so do make sure to get the right case
Copy linkTweet thisAlerts:
@andrettiFeb 16.2024 — Can you access MySQL database through the web Admin console? It may be that the password is incorrect for the user/password used to connect to the database from PHP file.

Have you tested with another account, like the "root" account?

&lt?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn -> connect_error) {
die("Connection failed: " . $conn -> connect_error);
}
echo "Connected successfully";
?>
×

Success!

Help @Carlauso spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...