你好,我有一個形式與許多輸入(名稱,姓氏,圖片,年齡..),我想提交所有這些信息到我的數據庫,我知道如何做一個簡單的輸入,但與圖片,我有一些問題 有人可以幫助我,請我 HTML文件插入圖片到數據庫使用php
<form action="insertion.php" method="post" >
<table >
<tr>
<td><strong>Titre</strong></td>
<td><input name="titre" type="text" value="" /></td>
</tr>
<tr>
<td><strong>Annee</strong></td>
<td><input name="annee" type="number" value="" /></td>
</tr>
<tr>
<td><strong>Genre musical</strong></td>
<td><input name="Gmusical" type="texte" value="" /></td>
</tr>
<tr>
<td>
<strong>Picture</strong>
</td>
<td>
<input type="file" name="img"/>
</td>
</tr>
</table>
<input type="submit" value="Submit " />
</form>
我的文件insertion.php到sublmit到數據庫
<?php
include("connexion.php");
$titre=$_POST['titre'];
$annee=$_POST['annee'];
$Gmusical=$_POST['Gmusical'];
$picture=$_POST['img'];
$req="INSERT INTO `cd`
(`titre`, `Annee`, `genremusical`, `Image`)
VALUES
('$titre','$annee','$Gmusical','$picture');";
if (mysql_query($req))
{
echo "ok";
}
else
echo 'ko';
}
你可能需要看到這個http://stackoverflow.com/questions/17153624/using-php-to-upload-file-and-add-the-path-to-mysql - 數據庫 –
旁註:爲了處理與圖像相關的表單,你的表單需要包含'enctype ='multipar t/form-data''首先。加上這個'$ picture = $ _ POST ['img'];'應該很可能是'$ picture = $ _ FILES ['img'];' –
您不應該將二進制圖像數據存儲到數據庫。只需將它們保存爲圖像文件並將路徑/文件名保存到數據庫即可。 – djot