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

Categories

0 votes
987 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 Reply

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="" />";


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...