Field 'photo' doesn’t have a default value

Asked

Viewed 144 times

0

I’m trying to make a insert from a photo to my database but every time I finish filling the fields and enter the error:

Field 'foto' doesn't have a default value

I couldn’t find out if the lack of value was in the database or in the HTML itself but I noticed that the user and password fields are still entered except for the photo field.

Follow the code lines below next to the database table I am entering

index php.

<html>
<head>
   <title>Cadastro paciente</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
   <?php include_once 'conexao.php'; 
   if(isset($_POST['usuario'])&& isset($_POST['senha'])&&isset($_POST['foto'])){

      $nome= $_POST['usuario'];
      $senha= $_POST['senha'];
      $foto= $_POST['foto'];

      try{
         $username='root';
         $password='';
         $pdo= new PDO('mysql:host=localhost;dbname=pit',$username,$password);
         $pdo->setAttribute(PDO::AFTER_ERRMODE,PDO::ERRMODE_EXPECTATION);
         $stmt=$pdo->prepare('INSERT INTO login_e_cadastro VALUES(:usuario,:senha,:foto)');
         $stmt->execute(array(

            ':usuario'=>$usuario,
            ':senha'=>$senha,
            ':foto'=>$foto,


         ));
         if ($stmt->rowCount() > 0) {
            echo "<script>alert('paciente cadastrado');</script>";
         }
      } catch(PDOException $e){
         echo 'Error:'.$e->getMessage();

      }
   }
?>

<div class="container">
   <div class="row">
      <div class="col-12">
         <div class="card-body space">
         <h3 align="center" class="card-title">Cadastro Paciente</h3>
            <form action="" method="post" >
               <div class="form-group">
                  <label>Nome:</label>
                  <input type="usuario" class="form-control" name="usuario" required>
               </div>
               <div class="form-group">
                  <label>senha:</label>
                  <input type="password" class="form-control" name="senha" required>
               </div>
               <input type="file" name="foto">
               <div align="center">
                  <input type="submit" value="cadastrar-se" class="btn btn-primary text-center" name="salvar">
                  <a class="btn btn-danger text-center" href="javascript:history.back()"> Voltar</a>
               </div>
            </form>
         </div>
      </div>
   </div>
</div>

</body>
</html>

php connection.

<?php

$mysqli = new mysqli('localhost', 'root', '', 'pit') or die(mysqli_error($mysqli));

    if (isset($_POST['salvar'])) {
        $usuario = $_POST['usuario'];
        $senha = $_POST['senha'];

        $mysqli->query("INSERT INTO login_e_cadastro (usuario, senha) VALUES('$usuario','$senha')") or die($mysqli->error);
    }


?>

Database table
inserir a descrição da imagem aqui

ERROR
inserir a descrição da imagem aqui

No answers

Browser other questions tagged

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