Phpmyadmin does not save file if you already have one saved

Asked

Viewed 98 times

0

I made a code to save the name of a file in the Phpmyadimn database, it works if the table is empty, but when I try to attach another file it 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’s 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!';
    }

?>

  • Put this on, echo mysqli_error($link); before the echo 'Erro ao...

  • What is the error? and what is the structure of your table?

  • Just to give you an idea, does the name of the second file you’re trying to send have a different name? If you try with a file of the same name, have you tried to verify that the table is not programmed to prevent equal names? Or try also with different email, to check that it is not the email that can not repeat.

  • @Fernandovr Sorry for the delay, I had some personal problems, I put mysqli_error, but there is no error regarding the connection, as for the restriction, I did not put any yet, and also tried with different files, remains the same problem. I use two tables in this database, one for user registration, it works normally, and another to attach files, which is what is giving this problem!

1 answer

0


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

Browser other questions tagged

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