title: insert multiple images to database using single submit button through php
body: <p>Here, i am trying to insert multiple images to database, but it is not happening with this code, i am inserting only the name of the image to database and move the images to a specific path. For a single image upload, its working, when i try to upload multiple images then it goes wrong. Please suggest me your ideas. Advance thanx to all. I am newbie in php, just trying to learn.</p>
  
  <pre><code> $img_name = $_FILES['banner']['name'];
   $img_size = $_FILES['banner']['size'];
   $img_temp = $_FILES['banner']['tmp_name'];
   $pht_name = $_FILES['photos']['name'];
   $pht_size = $_FILES['photos']['size'];
   $pht_temp = $_FILES['photos']['tmp_name'];
   $pht_name_a = $_FILES['photos_a']['name'];
   $pht_size_a = $_FILES['photos_a']['size'];
   $pht_temp_a = $_FILES['photos_a']['tmp_name'];
   $pht_name_b = $_FILES['photos_b']['name'];
   $pht_size_b = $_FILES['photos_b']['size'];
   $pht_temp_b = $_FILES['photos_b']['tmp_name'];
  
  include "_lib/_req/conn.php";
  // section 1 (page contents)
  $name = $pg_name . '_540x165_' . '.' . $img_ext;
  $path = "_img\\gallery\\540x165\\";
  $target_path = $path . $name;
  if(move_uploaded_file($img_temp, $target_path)){
  $insert = "INSERT INTO page_content (p_c_id, p_c_name, p_c_link, p_c_group, p_c_text, p_c_img, p_c_tag) 
  VALUES ('', '$pg_name', '$pg_link', '$pg_group', '$text', '$name', '$pg_tag')";
  $query = mysql_query($insert);              
  }
  else{ die(mysql_error()); }
  $md5_6 = substr(md5(rand()),0,6);
  $name_a = $pg_name . '_258x130_' . $md5_6 . '.' . $pht_ext;
  $path_a = "_img\\gallery\\258x130\\";
  $target_path_a = $path_a . $name_a;
  if(move_uploaded_file($pht_temp, $target_path_a)){
      $insert_a = "INSERT INTO page_photos (p_p_id, p_p_name, p_p_img) 
      VALUES ('', '$pg_name', '$name_a')";
      $query_a = mysql_query($insert_a);
  }
  else{ die(mysql_error()); }
  // page photo no.2
  $md5_7 = substr(md5(rand()),0,7);
  $name_b = $pg_name . '_258x130_' . $md5_7 . '.' . $pht_ext_a;
  $path_b = "_img\\gallery\\258x130\\";
  $target_path_b = $path_b . $name_b;
  if(move_uploaded_file($pht_temp_a, $target_path_b)){
      $insert_b = "INSERT INTO page_photos (p_p_id, p_p_name, p_p_img) 
      VALUES ('', '$pg_name', '$name_b')";
      $query_b = mysql_query($insert_b);
  }
  else{ die(mysql_error()); }
  </code></pre>