0

I am using PHP to create a user in my database, but even though there are no False statements or Errors in the PHP code, no user is created (even though it prompts me signup=success). I think the problem is the Mysql part, maybe I defined the dates as the wrong datatype? (I tried both s and i in bind_param). How do I retrieve the error message on the Mysql part, if mysqli_stmt_execute doesn't succeed?

This is my code:

$insertsql = "INSERT INTO users (emailUsers, pwdUsers, f_name, l_name, istenant, date_created, date_modified) VALUES (?, ?, ?, ?, ?, ?, ?)";
                $stmt = mysqli_stmt_init($mysqli);
                if (!mysqli_stmt_prepare($stmt, $insertsql)) {
                    header("Location: ../signup.php?error=sqlerror");
                    exit();
                } else {
                    $hashedpwd = password_hash($pwd, PASSWORD_DEFAULT);
                    mysqli_stmt_bind_param($stmt, 'sssssii', $mailid, $hashedpwd, $f_name, $l_name, $istenant, $date, $date);
                    mysqli_stmt_execute($stmt);
                    $display_block = printf("Error: %s.\n", mysqli_stmt_error($stmt));
                    header("Location: ../signup.php?signup=success");
                    exit();
                }
  • 1
    A good question to ask. Basically you need two things: configure mysqli to throw exceptions and **stop using procedural mysqli**. It has issues with reporting errors. – Your Common Sense Oct 15 '20 at 16:46
  • *"How do I retrieve the error message on the Mysql part, if mysqli_stmt_execute doesn't succeed?"* - Haven't you do that already with `$display_block = printf("Error: %s.\n", mysqli_stmt_error($stmt));`? Edit: Wait a minute. That won't throw an error because you're inside what's to be a successful insert. – Funk Forty Niner Oct 15 '20 at 16:50
  • Thank you 'Your Common Sense'. It helped me with my problem! –  Oct 15 '20 at 21:40

0 Answers0