Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
895 views
in Technique[技术] by (71.8m points)

mysql - Insert picture into database using php

hello i have a form with many input ( name, last name, picture,age..) and i want to submit all this information into my database , i know how to do it for a simple input but with the picture i have some problem can someone help me please my html file is

<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>

my file insertion.php to sublmit into the database is

<?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';
            }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Generally you do not want to store actual BLOB(binary large object) data types in a database. You store the path to the image, located somewhere on your web server.

So in the column "Image", you would store the path "images/photo1103.jpg".

To display the photo: echo "<img src=". $image_query_fetch['Image'] .'" alt="" />";


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...