Problem adding photo to database, what to do?

Asked

Viewed 52 times

0

I choose a photo through this part of the code on a php page:

<label for="foto">Foto:</label>
<input type="file" name="foto"><br><br>

And then I need to register her in a blob field in the database, I’m using this:

if($foto != NULL) { 
    $nomeFinal = time().'.jpg'; 
    if (move_uploaded_file($foto['tmp_name'], $nomeFinal)) {
        $tamanhoImg = filesize($nomeFinal);
        $mysqlImg = addslashes(fread(fopen($nomeFinal, "r"), $tamanhoImg));
        mysql_connect($host,$user,$pass) or die("Impossível Conectar"); 
        @mysql_select_db($banco) or die("Impossível Conectar"); 

        $sql = mysql_query("INSERT INTO jogador(nomej, foto, nometime)
        VALUES('$nomej', 'mysqlImg','$nometime')")
        or die("O sistema não foi capaz de executar a query");

        unlink($nomeFinal);
        header("location:addjogador.php");
    } 
} else { echo"Você não realizou o upload de forma satisfatória."; 

what I’m doing wrong?

  • 1

    What problem? doesn’t work? doesn’t save? error?

2 answers

1

Note that in the Query mysqlImg is like a string, not the variable itself. I think that’s it.

0

You need to add enctype to the FORM element: For example:

    <form action="script.php" method="POST" enctype="multipart/form-data"> 
       Seu arquivo: 
       <label for="foto">Foto:</label>
       <input type="file" name="foto"><br><br>
    </form>

Browser other questions tagged

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