-3
if ($stmt = $connection->prepare('INSERT INTO users (name, id, password, email, city, avatar, about, activation_code) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')) {
        $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
        $uniqid = uniqid();
        $stmt->bind_param('ssssssss', $_POST['name'], $_POST['id'], $password, $email, $_POST['city'], $_POST['avatar'], $_POST['about'], $uniqid);
        $stmt->execute();
        $stmt->store_result();
        echo 'Account's created';
    } else {
        echo 'Error';
    }

This part of code doesn't create user in myqsl db. But if I This code:

$stmt->bind_param('ssssssss', $_POST['name'], $_POST['id'], $password, $email, $_POST['city'], $_POST['avatar'], $_POST['about'], $uniqid);

Replace with:

$stmt->bind_param('ssssssss', $_POST['name'], $_POST['id'], $email, $password, $_POST['city'], $_POST['avatar'], $_POST['about'], $uniqid);

It create user but in table in email there is password and in password - email. How I can fix it???

Dharman
  • 21,838
  • 18
  • 57
  • 107
anraow
  • 1
  • 2
  • 2
    Do you see any errors/warnings/notices? If you're unsure how to check for errors, see [this post](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). Also, here's a thorough [tutorial](https://stackoverflow.com/a/22662582/4205384) on debugging db related problems. – El_Vanja Apr 04 '20 at 10:11
  • 2
    You also have a syntax error here: `echo 'Account's created';`, that inner single quote should be escaped. – El_Vanja Apr 04 '20 at 10:12
  • 1
    Are there any restrictions on columns? Might be your email field needs to be unique and an entry already exists when using your first query – brombeer Apr 04 '20 at 10:30
  • 1
    Check for errors with mysqli. – u_mulder Apr 04 '20 at 10:36
  • 1
    Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Apr 04 '20 at 11:59

2 Answers2

2

You need to check out what the error reported by MySQL says.

Not having seen your table definition (you really should post that too), I can only guess that the password you use - the hash - being as it is a PK2DBF hash, is too long for the password field.

You probably reserved something like 64 chars for the email and, what do I know, 16 characters for the password. But the password hash is longer. So if you insert the password in the email column it fits, the other way it doesn't.

You should use something like VARCHAR(200) for the password column definition field.

LSerni
  • 49,775
  • 9
  • 56
  • 97
  • 1
    This is likely to be the cause. And it also illustrates why coding by guessing is a ridiculous methodology—just allow the computer to tell you what the problem is! :) – Álvaro González Apr 04 '20 at 11:31
  • thank u so much, you was right. There's a problem with password's lenght and also error with samiliar email in db. So I solve it, thank u – anraow Apr 04 '20 at 17:54
0

check the sql datatypes of the email and password columns and their respective lengths, the hash generated is probably too long or the email column does not allow certain inputs.

codefather
  • 96
  • 10