Error "Doesn’t have a default value" when trying to insert data into DB

Asked

Viewed 2,736 times

5

I was trying to enter the variables I received from a form when I received this error message:

'nidcrespons1' doesn’t have a default value

My code:

<?php
    $link = mysqli_connect("localhost", "root", "vertrigo", "winit");
    $nomeempresa = $_POST["nomeempresa"];
    $paisempresa = $_POST["paisempresa"];
    $moradaempresa = $_POST["moradaempresa"];
    $nifempresa = $_POST["nifempresa"];
    $crc = $_POST["crc"];
    $telefoneempresa = $_POST["telefoneempresa"];
    $respons1 = $_POST["respons1"];
    $nidcrespons1 = $_POST["nidcrespons1"];
    $nifrespons1 = $_POST["nifrespons1"];
    $emailempresa = $_POST["emailempresa"];
    $senhaempresa = $_POST["senhaempresa"];

    echo $nomeempresa;
    echo $paisempresa;

    $insere = mysqli_query($link, "INSERT INTO empresas (nomeempresa, respons1) VALUES ('$nomeempresa', '$respons1')") or die(mysqli_error($link));
?>
  • 2

    Pass a value p it, must come from the form, do this for all columns.

  • The problem is this same, puts it as an answer for me to give score.

  • 1

    You can create an answer :)

  • 4

    It’s not about the question, but here’s the tip: Prepared statements in your SQL code.

1 answer

7


The problem is that you have to pass some value to the database columns that are NOT NULL, the column can not be without anything, ie the INSERT have to have something to fill the column.

Browser other questions tagged

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