Form does not insert data into the BD

Asked

Viewed 18 times

0

I have an HTML FORM and it does not send data to the BD

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="author" content="João Bastos">
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
    ThunderIT
  </title>
</head>
  <body>
  <form action="phpcodes/fichacliente.php" method="post">
  <label for="name">First name:</label><br>
  <input type="text" id="nome" name="nome"><br>
  <label for="morada">Morada</label><br>
  <input type="text" id="morada" name="morada"><br><br>
  <label for="codPostal">codPostal</label><br>
<input type="text" id="codPostal" name="codPostal"><br><br>
  <label for="email">email</label><br>
<input type="text" id="email" name="email"><br><br>
  <label for="contacto">contacto</label><br>
<input type="text" id="contacto" name="contacto"><br><br>
  <label for="cidade">cidade</label><br>
<input type="text" id="cidade" name="cidade"><br><br>
  <label for="empresa">empresa</label><br>
<input type="text" id="empresa" name="empresa"><br><br>
<label for="nacionalidade">nacionalidade</label><br>
<input type="text" id="nacionalidade" name="nacionalidade"><br><br>
  <label for="nif">nif</label><br>
<input type="text" id="nif" name="nif"><br><br>
  <input type="submit" value="Submit" name="submit">
</form>
</body>

</html>

PHP FORM sending to BD

<?php
   require "BDi.php";

if (isset($_POST["submit"])) {
  $nome = $_POST['nome'];
  $morada = $_POST['morada'];
  $codPostal = $_POST['codPostal'];
  $email = $_POST['email'];
  $contacto = $_POST['contacto'];
  $cidade = $_POST['cidade'];
  $empresa = $_POST['empresa'];
  $nacionalidade = $_POST['nacionalidade'];
  $nif = $_POST['nif'];
  
              $stmt = $DB->prepare("INSERT INTO IMEI_fichacliente (`n_nif`, `nome`, `morada`, `codPostal`, `email`, `contacto`, `cidade`, 
                                    `empresa`, `nacionalidade`) VALUES (?,?,?,?,?,?,?,?,?)");
            $stmt->bind_param('sssssssss',$nome, $morada, $codPostal, $email, $contacto, $cidade, $empresa, $nacionalidade, $nif);
            $stmt->execute();
  
}
?>

The require BDI works pk tmb use on other pages. When I do Submit it goes to the PHP page but is empty and does not insert any information in the BD. How can I fix?

  • 1

    Already gave a print_r($_POST) or var_dump($_POST) to check if the data is there?

  • @Bernardolopes Yes, I tried it now and it collects the data but can not enter in the database

1 answer

0


I already solved the problem, in DB had an INT field and in the form I was inserting a text, so that was it

Browser other questions tagged

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