0

I'm a beginner in PHP development, I'm learning PHP this year in computer school, and I have to develop a site for the end of next week, problem is that I'm really struggling. Since I'm a beginner...

So, it's a registration thing, and when I register it tells me there's a problem with bind_param...

here are my codes:

<?php
$conn = new mysqli("localhost","user","password","database");

if(!$conn){
    echo 'Erreur de connexion: ' . mysqli_connect_error();
}

require 'database.php';

$message = '';

if (!empty($_POST['email']) && !empty($_POST['password'])) {
    $mysqli = "INSERT INTO users (email, password) VALUES (:email, :password)";
    $stmt = $conn->prepare($mysqli);
    $stmt->bind_param(':email', $_POST['email']);
    $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
    $stmt->bind_param(':password', $password);

    if ($stmt->execute()) {
        $message = 'Félicitation, vous avez réussi à créer un nouvel utilisateur.';
    } else {
        $message = 'Désolé, un compte a déjà été créé avec la même adresse mail.';
    }
}
?>

I'm really a beginner, so please bear with me, because I don't want to miss my homework because of a problem with BIND_PARAM.

I'm using MariaDB as a database, I don't know if it helps if I say what I'm using as a database.

Mohile
  • 1
  • If you are only starting to learn PHP then you should learn PDO instead of mysqli. PDO is much easier and more suitable for beginners. Start here https://phpdelusions.net/pdo & https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection – Dharman Feb 18 '21 at 21:18
  • Or you can check out this [code](https://github.com/DeathThreats/PHPLoginSystem/blob/master/auth/signup_auth.php) but it's written using OOP might be a big help though – Augustin Feb 19 '21 at 04:12

0 Answers0