0

I am a beginner in php and I want to submit the inputs to my database using this function. I checked everything including variables, ids.. everything. However, !mysqli_stmt_prepare($stmt, $sql) is always returning true. Means that there is something wrong why it cant store my inputs to my database.

createUser($conn, $name, $email, $username, $pwd);

function createUser($conn, $name, $email, $username, $pwd) {
    $sql = "INSERT INTO users (usersName, usersEmail, usersUid, usersPwd) VALUES (?, ?, ?, ?);";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        header ("location: ../signup.php?stmtfailed2");
        exit();
    }
    

    $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
    
    mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $username, $hashedPwd);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_close($stmt);
    header("location: ../signup.php?error=none");
    exit();

}
  • You should remove that `if` statement and just enable proper error reporting. – Dharman Oct 07 '21 at 22:06
  • 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 Oct 07 '21 at 22:06

0 Answers0