Problem when adding photo to database, what to do?

0

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

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

And then I need to register it 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 am I doing wrong?

    
asked by anonymous 09.10.2015 / 20:02

2 answers

1

Notice that in Query mysqlImg is a string, not the variable itself. I think that's it.

    
09.10.2015 / 20:39
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>
    
09.10.2015 / 20:39