Error due to upload of PHP files

Asked

Viewed 25 times

0

The data that already exists is displayed, but I can’t register new data.

    function inserirCliente(){
$retorno="";
    $conecta = DBConnect(); 
        if (isset($_POST['enviaCliente'])) 
        {
            //só para a imagem
           if (isset($_FILES['arquivo'])) {
                $extencao = strtolower(substr($_FILES['arquivo']['name'],-4));
                $diretorio ="upload/";
                $Nome_novo = md5(time()).$extencao;
                move_uploaded_file($_FILES['arquivo']['tmp_name'], $diretorio.$Nome_novo);                  

                $nome = $_POST["Nome"];
                $experiencia = $_POST["Anos"];
                $email=$_POST["Email"];
                $telefone =$_POST["numeroPhone"];
                $Biografia=$_POST["Biografia"];
                $cidade=$_POST["cidade"];

                $result_usuario = "INSERT INTO cadastro3 (nome,experiencia, email, telefone,cidade,Biografia,imagem) 
                VALUES ('$nome','$experiencia','$email','$telefone', '$cidade','$Biografia','$Nome_novo')"; 

                $Consulta = DBExecute($result_usuario);                 
                $conectando = DBConnect($result_usuario);
                $retorno = $conectando;}
                else{echo "imagem não detectada";}
        } else echo "cliente não inseridos";            
DBClose($conecta);
return $retorno;    
}

When I take the if file check gives error of Index :

Notice: Undefined index: file in C: xampp htdocs Constructesfree Dozero System funcoes.php on line 33

the file sending code is this :

  <?php 
  if (isset($_SESSION['Login']))
   { ?>  
<div class="container">
  <div class="page-header">
    <h2> Cadastrar novo cliente</h2>
   </div>      
</div>

<form class="container" action="#" method="post" enctype="multipart/form-data">
  <div class="form-group">
    <label>Nome completo</label>
    <input class="form-control" type="text" name="Nome">
  </div>
  <div class="form-group">
    <label>Anos de trabalho</label>
    <input class="form-control" type="number" name="Anos">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Endereço de e-mail</label>
    <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" name="Email">
  </div>  
  <div class="form-group">
      <label>Numero de telefone</label>
      <input type="number" class="form-control"name="numeroPhone">
  </div>
   <div class="form-group">
      <label>cidade</label>
      <input type="text" class="form-control"name="cidade">
  </div>
  <div class="form-group">
    <label for="exampleTextarea">Biografia</label>
    <textarea name="Biografia" class="form-control" id="exampleTextarea" rows="3"></textarea>
  </div>

  <div class="form-group">
    <label for="exampleInputFile">Imagem</label>
    <input type="file" name="MAX_FILE_SIZE" value="99999999" class="form-control-file" id="exampleInputFile" name="arquivo" aria-describedby="fileHelp">
    <small id="fileHelp" class="form-text text-muted">Escolha a imagem do tamanho especificado.</small>
  </div>  

  <button type="submit" name="enviaCliente" class="btn btn-primary">enviar</button>
</form>     
      <?php } inserirCliente(); ?>
  • 1

    In your HTML, you set the field name to name="MAX_FILE_SIZE", then in PHP it would be $_FILES['MAX_FILE_SIZE']. Looks like you got confused there.

  • Following @Andersoncarloswoss' comment, you have set the attribute twice name with different values.

  • guy can’t believe I messed this up, thanks I’m learning

No answers

Browser other questions tagged

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