Is there any way I can leave fields that have not been filled as null ? When creating the table, the fields have already been defined as DEFAULT NULL
, but when doing insert - in the MySQL database - by $ _ POST , the fields that were not filled remain empty.
Below is the code.
if (isset($_POST['update'])) { $nome = $_POST['nome']; $sobrenome = $_POST['sobrenome']; $nivel = $_POST['nivel']; $date = date('Y-m-d H:i:s'); $_SESSION['warning']['type'] = "success"; // tipos success, info, warning e error $_SESSION['warning']['message'] = "Player Created Successfully!"; // mensagem que vai aparecer if (empty($_POST['nome'])) { $_SESSION['warning']['type'] = "error"; // tipos success, info, warning e error $_SESSION['warning']['message'] = "The NAME is required."; // mensagem que vai aparecer echo "history.go(-1);"; exit; } $vsl = "INSERT INTO 'files' ('id', 'nome', 'sobrenome', 'nivel', 'date')VALUES(NULL, '$nome', '$sobrenome', '$nivel', '$date')"; $rsl = mysqli_query($conn, $vsl); header("Location: add.php"); exit(); }