Phpmyadmin does not save a file if you already have one saved

0

I made a code to save the name of a file in the database PhpMyAdimn, it works if the table is empty, but when I try to attach another file to the error, does anyone have any idea why this occurs? Remembering that the file is saved in the folder, only the part of the database that gives error.

Here is the connection to the bank I used:

<?php

class db {
    //host
    private $host = 'localhost';

//usuario
private $usuario = 'nome';

//senha
private $senha = '123456';

//banco de dados
private $database = 'banco';

public function conecta_mysql(){

    //criar a conexão
    $con = mysqli_connect($this->host, $this->usuario, $this->senha, $this->database);

    //ajustar a charser de cominicação entre a aplicação e o bd
    mysqli_set_charset($con, 'utf8');

    //verificar se houve erro de conexão
    if (mysqli_connect_errno()) {
        echo 'Erro ao tentar se conectar com o banco de dados'.mysqli_connect_error();
    }

    return $con;
}
}
?>

And this is php code to send and receive the file:     

  session_start();

  require_once('conecta.php');

  if (isset($_POST['enviar'])) {


    move_uploaded_file($_FILES['arquivo']['tmp_name'], 'uploads/'.$_FILES['arquivo']['name']);

    $arq = $_FILES['arquivo']['name'];
    $email = $_SESSION['email'];

    $objDb = new db();
    $link = $objDb->conecta_mysql();
    $sql = "insert into arquivos (email_vol, nomearq) values ('$email', '$arq')";
    if (mysqli_query($link, $sql)){
      echo 'Arquivo enviado com sucesso!';
    } else {
      echo 'Erro ao enviar o arquivo!';
    }

  } else {
    echo "Nenhum arquivo selecionado!";
  }

  $sel = "SELECT nomearq FROM arquivos WHERE email_vol = '$email'";
  if (mysqli_query($link, $sel)){

    } else {
      echo 'Erro ao enviar o arquivo!';
    }

?>
    
asked by anonymous 09.10.2017 / 15:12

1 answer

0

I managed to solve the problem, what happens is that I had defined the email variable as being primary key, so it did not accept the upload of other files !!!

    
19.10.2017 / 16:15