my code cannot send all image data.
it sends odd or even no of data.please help


if (isset($_POST['submit'])) {
    $j = 0; //Variable for indexing uploaded image 
    $target_path = "uploads/"; //Declaring Path for uploaded images
    if (count($_FILES['file']['name'])<6)
    for ($i = 0; $i < $k; $i++) {//loop to get individual element from the array count($_FILES['file']['name'])

        $validextensions = array("jpeg", "jpg", "png");  //Extensions which are allowed
        $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) 
        $file_extension = end($ext); //store extensions in the variable

        $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];//set the target path with a new name of image

        $sql="UPDATE ads SET $img='$target_path' WHERE id='$id'";
        echo $img;

        $j = $j + 1;//increment the number of uploaded images according to the files in array       

      if (($_FILES["file"]["size"][$i] < 500000) //Approx. 500kb files can be uploaded.
                && in_array($file_extension, $validextensions)) {
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else {//if file was not moved.
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
        } else {//if file size and file type was incorrect.
            echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
    if (!mysql_query($sql,$con))
  die('Error: ' . mysql_error());

Set your html code here to we know what is your problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.