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'
Probably the informed company id does not exist in the company table.
– rray
you are making an insert and the
idusuario
cannot be NULL, (empty)– RFL
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
– GustavoSevero
The primary key is the
idUsuario
andempresa_idempresa
?– rray