php - Data insert and Image Upload -


I am trying to insert some data from the text area in MySQL and upload an image to a specific folder I can save my name in MySQL but when I submit it, only text area data (Tituli, Parmajjatja) is inserted into the database, the image is not uploaded and the image name is not entered in MySQL. The form code is:

  & lt; Form role = "form" method = "post" action = "shtolajm1.php" enctype = "multipart / form-data" & gt; & Lt; Div class = "form-group" & gt; & Lt; Textarea class = "form-control" rows = "3" name = "titulli" & gt; & Lt; / Textarea & gt; & Lt; Textarea class = "form-control" rows = "10" name = "permbajtja" & gt; & Lt; / Textarea & gt; & Lt; Input type = "file" name = "files []" style = "margin-left: -5;" /> & Lt; Button type = "submit" name = "submit" class = "btn btn-default" style = "float: right; margin-top: 10px;" & Gt; Insert & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Form & gt;  

And here is the code that ISM is using to add data to mysql and upload photos:

  if (isset ($ _ POST) ['Submit']) (if (strlen (trim ($ _ POST ['titulli'])) == 0 & amp;! Strlen (trim ($ _ POST ['permbajtja'])) == 0) {$ Titulli = $ _POST ['titulli']; $ Permbajtja = $ _ post ['permbajtja']; $ data = date ('y-m-d'); $ time = date ('h: i'); $ User name = $ _ session ['myusername']; $ InsertQuerry = "LASSEY (titulli, permbajtja, data, ora, useri) VALUES ('$ titulli', '$ permbajtja', '$ data', '$ time' , '$ Username'); "if (mysql_query ($ InsertQuerry)) {echo" inserted data ";}} Else {echo "Title and Container Type";}} $ Id_lajmi = mysql_insert_id (); $ I ++) ($ ($ _ files ['file'] ['name'])) {To ($ i = 0; $ i & Lt; Count ($ _ files ['files'] ['name']); $ i ++ {$ TmpFilePath = $ _FILES ['file'] ['tmp_name'] [$ i]; if ($ tmpFilePath! = "") {$ Path = "lajme_foto /"; list ($ txt, $ ext) = explosion (".", $ Name); If (move_uploaded_file ($ _ files ['files'] ['tmp_name'] [$ i], $ path. $ Id_lajmi. "Photo" $ I. "." $. $ Ext)) {$ emri_fotos = $ path . $ Id_lajmi "picture" $ i $ ext ... "." $ Insertfoto = "Include in Lazy_photo (id_lajmi, emri_fotos) values ​​('$ id_lajmi', '$ emri_fotos')"; If (mysql_query ($ insertfoto)) {echo "insert image"; }}}}}  

Can someone help me solve this problem? Thanks in the advice.

You forgot to add enctype = "multipart / form-data" In your form

Your form tag should look like this: form role = "form" method = "post" action = "shtolajm1.php" enctype = "multipart / form-data" & gt;


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -