Workbench enters wrong data

Viewed 19

I recently developed a small registration system in PHP and MySQL. In tests, it worked perfectly. However, from the first successful test, the workbench started to have problems.

Every time I enter a registration, either via PHP, or directly in the workbench, the workbench inserts the number 127 in the primary key, which, if I'm not mistaken, was the last random number I entered for testing purposes, when the test was successful.

I currently use XAMPP as a server for PHP and MySQL. I already restarted it, I already changed the server to MySQL80 and I also restarted the computer, but nothing helped.

The following is the PHP code, the "user" table and the tests in the workbench with their result, respectively:

<?php
// Recepção de dados de cadastro.html
require_once("conexao.php");

$matricula = $_POST['inputMatricula'];
$nome = $_POST['inputNome'];
$email = $_POST['inputEmail'];
$senha = $_POST['inputSenha'];
$login = $_POST['inputLogin'];

echo $matricula;

// Inserção de dados no BD
$result = $conn->query("INSERT INTO usuario 
    VALUES ('{$matricula}', 'Informática', 'Vespertino', '{$nome}', '{$email}', '{$senha}', '{$login}')");

The usuario table:

Table "usuario"

The contents of the usuario table:

SELECT (No data in the table)

The INSERT command:

INSERT INTO usuario 
    VALUES (1234567890123456, 'Informática', 'Vespertino', 'nome', 'email', 'senha', 'login');

Query Results:

Result

Did you see? How should I proceed?

1 Answers

127 is the maximum value for a signed TINYINT column like you're using in your table. You need to use a larger data type for your primary key column.

From the MySQL documentation page on Integer Types:

Type Storage (Bytes) Minimum Value Signed Minimum Value Unsigned Maximum Value Signed Maximum Value Unsigned
TINYINT 1 -128 0 127 255
SMALLINT 2 -32768 0 32767 65535
MEDIUMINT 3 -8388608 0 8388607 16777215
INT 4 -2147483648 0 2147483647 4294967295
BIGINT 8 -263 0 263-1 264-1

If you're really planning on storing 16 digit integers in your primary key column, and you know they'll never be negative, then I'd recommend using UNSIGNED BIGINT.

Related