Uncaught Exception 'Pdoexception' with message 'SQLSTATE[23000]: Integrity Constraint Violation: 1048

Asked

Viewed 654 times

0

I am trying to make a simple entry in the database, as I have done several times, using PDO and I can’t! What’s wrong?

PHP:

<?php
include_once("con.php");

$pdo = conectar();

$data = file_get_contents("php://input");
$data = json_decode($data);

$opcao = $data->opcao;
$email = $data->email;
$senha = $data->senha;
$nome = $data->nome;
$usuario = $data->user;
$idempresa = $data->idempresa;

$insereUsuario=$pdo->prepare("INSERT INTO usuario (idusuario, usuario, senha, email, empresa_idempresa, nome)
                         VALUES (?, ?, ?, ?, ?, ?)");
$insereUsuario->bindValue(1, NULL);
$insereUsuario->bindValue(2, $usuario);
$insereUsuario->bindValue(3, $senha);
$insereUsuario->bindValue(4, $email);
$insereUsuario->bindValue(5, $idempresa);
$insereUsuario->bindValue(6, $nome);
$insereUsuario->execute();

Error message:

Fatal error: Uncaught Exception 'Pdoexception' with message 'SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'idusuario' cannot be null'

My chart in the comic book table usuario

  • Probably the informed company id does not exist in the company table.

  • you are making an insert and the idusuario cannot be NULL, (empty)

  • From what I checked earlier, the company id is coming yes. Yes, I understand that idusuario cannot be null... Normal. But look at my insert command! Nothing’s wrong! It’s not null

  • The primary key is the idUsuario and empresa_idempresa?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.