MySQL PhP connection don't work

Hi, i want to create a member space in my website

The Code for the db connection is

<?php $pdo = new PDO('mysql:dbname=id11368693_membres;host=localhost', 'id11368693_zirvax', 'secrets'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); And for the insert in data base if(empty($errors)) { require'inc/db.php'; $req = $pdo->prepare("INSERT INTO users SET username = ?, password = ?, email = ?"); $password = password_hash($_POST['password'], PASSWORD_BCRYPT); $req->execute([$_POST['username'], $password, $_POST['email']]); die('Le compte a ete creer'); } It is'nt work, can you help me ?

Working fine - see

Thanks so much ! You save my life

1 Like

So how can i add it in my code ? Because, it don’t add members in the database…

I’m not sure I’ll have another look not sure though.

What do you mean ? You can’t do this ? Please…

I can see that database is working fine using PDO.

So I can only assume you need to modify your code somehow?

Works here? :slight_smile:

I just want to complete the code with the code I already made …

1 Like

Gotcha, you always need to define host, username, database name and password.

Basically I can remove the try and the catch

I’m not sure what you mean?

Your script works fine.

When you remove the database name and you keep leaving $database = “”;

This is when the script doesn’t insert the user.

Correct code

Just, thanks you so much, i love you

1 Like