I need help to insert an image in SQL and then recall it on HTML. I'm currently trying to insert the image into the database, returning this error
"Error sending the file. Please try again! Fatal error: Uncaught Error: Call to undefined function mysql_connect () in /membri/tiservo/inserimentooprodotti/image/write_db.php:10 Stack trace: # 0 {main} thrown in /membri/tiservo/inserimentoprodotti/image/write_db.php online 10 "
Where have I gone wrong? to others it works
P.S I will not insert the code to call the image in HTML as I have not yet tried if it works.
HTML FORM:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Carica file nel DB</title>
</head>
<body>
<form name="upload" action = "write_db.php" method = "POST" enctype = "multipart/form-data">
<input type="submit" name="invia" value="Invia file">
<input type = "file" name = "file_inviato" />
<input type = "submit"/>
</form>
</body>
</html>
PHP:
<?php
// Verifico eventuali problemi nell'upload del file
if ((!isset($_FILES["file_inviato"])) || ($_FILES["file_inviato"]["error"] != UPLOAD_ERR_OK))
echo("Errore nell'invio del file. Riprova!");
// Connessione e selezione del database
mysql_connect("localhost", "MYUSER", "")
or die("Connessione non riuscita: " . mysql_error());
if (!mysql_select_db("MY_DB"))
die("Selezione database fallita!");
// Recupero delle informazioni sul file inviato
$nome_file_temporaneo = $_FILES["file_inviato"]["tmp_name"];
$nome_file_vero = $_FILES["file_inviato"]["name"];
$tipo_file = $_FILES["file_inviato"]["type"];
// Leggo il contenuto del file
$dati_file = file_get_contents($nome_file_temporaneo);
// Preparo il contenuto del file per la query sql
$dati_file = addslashes($dati_file);
// Query per inserire il file nel DB
$query = "INSERT INTO tabella_file SET
nome = '$nome_file_vero',
tipo = '$tipo_file',
dati = '$dati_file'";
mysql_query($query)
or die("Query non valida: " . mysql_error());
// Messaggio di successo
echo("Memorizzazione del file <b>$nome_file_vero</b> nel database eseguita correttamente!");
Edit
Thanks for all the answers you have given me, I didn't know that it was no longer supported. I change the question so that someone can help me further.
Could you give me a working code simply to take the image insert it in the database and then recall it from HTML.