php - Multitple Image upload can not save descriptions into database. How to fix this? -


i trying create multiple image upload description on each image. have used jquery coe allows me add fields on demand. however, though images uploaded , saved db, in description column array[0] instead of actual description..

how can fix this?

this html

<form action="upload.php" method="post" enctype="multipart/form-data"> <div class="input_fields_wrap"> <button class="add_field_button">add more fields</button>    <div><input type="file" name="file_array[]"><input type="text" name="description[]" placeholder="write description"></div>    </div>     <input type="submit" value="upload files"> </form> 

and here upload.php

if(isset($_files['file_array'])){     $name_array = $_files['file_array']['name'];     $tmp_name_array = $_files['file_array']['tmp_name'];     $type_array = $_files['file_array']['type'];     $size_array = $_files['file_array']['size'];     $error_array = $_files['file_array']['error'];     for($i = 0; $i < count($tmp_name_array); $i++){         if(move_uploaded_file($tmp_name_array[$i], "upload/".$name_array[$i])){         mysql_query("insert projects (`image`,`description`) values('$name_array[$i]','$_post[description][$i]') ");             echo $name_array[$i]." upload complete<br>";         } else {             echo "move_uploaded_file function failed ".$name_array[$i]."<br>";         }     } } 

you need add description in quotes. query be.

mysql_query("insert projects (`image`,`description`) values('".$name_array[$i]."','".$_post['description'][$i]."') "); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -