title: Issue with image upload php: undefined index
body: <p>I am having trouble getting the image upload feature to work on the code below with the following error meesage:</p>
  
  <p><em>'An error occurred in script '/database.php' on line 135:
  Undefined index: image'</em> </p>
  
  <p>which is this part:  <strong>'if (is_uploaded_file ($_FILES ['image']['tmp_name'])) {'</strong> </p>
  
  <p>I've done a few php/mysql forms before but this is the first time I've tried to use image uploads. If possible I'm after a form that allows pdfs and jpegs only and limits the upload to 1.5 meg. </p>
  
  <p>The rest of the form works ok, other than that, I have changed the CHMOD to 777 on the uploads folder on the server. Any ideas or suggestions?</p>
  
  <pre><code>&lt;?php # index.php
  require_once ('./includes/config.inc.php');
  $page_title = 'N-Club Battery: Add a Sale';
  include ('./includes/header.html');
  if (!isset($_SESSION['sp_user_id'])) {
  $url = 'http://' . $_SERVER['HTTP_HOST']
  . dirname($_SERVER['PHP_SELF']);
  if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
  $url = substr ($url, 0, -1); // Chop off the slash.
  }
  $url .= '/login.php'; 
  ob_end_clean(); // Delete the buffer.
  header("Location: $url"); 
  exit(); // Quit the script.
  }
  $users = $_SESSION['sp_user_id'];
  ?&gt;
  &lt;h1&gt;Heading&lt;/h1&gt;
  &lt;?php
  if (isset($_POST['submitted'])) {// Handle the form.
  require_once ('/database.php');
  $errors = array(); // Initialize error array.
  
  // Check for a quantity.
  if (empty($_POST['npc_quantity'])) {
  $errors[] = '&lt;p&gt;• You forgot to enter the Quantity.&lt;/p&gt;';
  } else {
  $quantity = escape_data($_POST['npc_quantity']);
  }
  
  // Check for a customer name.
  if (empty($_POST['npc_customer_name'])) {
  $errors[] = '&lt;p&gt;• You forgot to enter the Customer Name&lt;/p&gt;';
  } else {
  $customers = escape_data($_POST['npc_customer_name']);
  }
  
  // Check for an registration number
  if (empty($_POST['npc_registration_no'])) {
  $errors[] = '• You forgot to enter the Customer Rego Number.';
  } else {
  $rego = escape_data($_POST['npc_registration_no']);
  }
  
  // Check for an SUO number
  if (empty($_POST['npc_suo_no'])) {
  $errors[] = '• You forgot to enter the SUO Number';
  } else {
  $suo_no = escape_data($_POST['npc_suo_no']);
  }
  
  // Check for an A-Club number
  if (empty($_POST['npc_amb_club_no'])) {
  $errors[] = '• You forgot to enter the A-Club Number';
  } else {
  $amb_no = escape_data($_POST['npc_amb_club_no']);
  }
  
  // Check for a Repair Order
  if (empty($_POST['npc_repair_order'])) {
  $errors[] = '• You forgot to enter the Repair Order';
  } else {
  $rep_no = escape_data($_POST['npc_repair_order']);
  }
  
  // Check for a Invoice Number.
  if (empty($_POST['npc_invoice_no'])) {
  $errors[] = '&lt;p&gt;• You forgot to enter the Invoice Number.&lt;/p&gt;';
  } else {
  $inv = escape_data($_POST['npc_invoice_no']);
  }
  
  // Check for a userdate.
  if (empty($_POST['npc_entry_userdate'])) {
  $errors[] = '&lt;p&gt;• You forgot to enter the entry userdate.&lt;/p&gt;';
  } else {
  $inv_date = escape_data($_POST['npc_entry_userdate']);
  }
  
  // Check for an image.
  if (is_uploaded_file ($_FILES ['image']['tmp_name'])) {
  if (move_uploaded_file($_FILES ['image']['tmp_name'], 
  "/uploadsfolder/{$_FILES['image']['name']}")) { // Move the file over.
  
  echo '&lt;p&gt;The file has been uploaded!&lt;/p&gt;';
  
  } else { // Couldn't move the file over.
  echo '&lt;p&gt;&lt;font color="red"&gt; The thumbnail image could not be uploaded.&lt;/font&gt;&lt;/p&gt;';
  $i = FALSE;
  }
  $i = $_FILES['image']['name'];
  } else {
  $i = FALSE;
  }
  
  if (empty($errors)) { 
  
  $uid = @mysql_insert_id(); 
  
  // Add the user.
  $query = "INSERT INTO npc_sales_list 
  (npc_item_id , sp_user_id, npc_battery_n_code, npc_battery_other_code, npc_quantity , 
  npc_customer_name, npc_registration_no , npc_suo_no, npc_amb_club_no , npc_repair_order, 
  npc_invoice_no, npc_entry_userdate, npc_image_upload, npc_usertype, 
  npc_points, npc_bonus_points, npc_entry_date) VALUES
  ('$uid', '$users', '$_POST[npc_battery_n_code]' , 
  '$_POST[npc_battery_other_code]' , '$quantity' , '$customers', 
  '$rego' , '$suo_no' , '$amb_no', '$rep_no', '$inv', '$inv_date', 
  '$i' , Battery' , '5' , '0' , NOW())";
  $result = @mysql_query ($query); // Run the query.
  
  if (mysql_affected_rows() == 1) {
  
  //Finish the page.
  echo '&lt;p&gt;The sale with invoice number: &lt;strong&gt;' . $inv . '&lt;/strong&gt;&lt;br /&gt;
  is now registered into the system.&lt;/p&gt;';
  include ('./includes/footer.html'); // Include the HTML footer.
  exit();
  
  } else { // If it did not run OK.
  echo '&lt;p&gt;&lt;font color="red" size="+1"&gt;You could not be
  registered due to a system error. We apologize for any
  inconvenience.&lt;/font&gt;&lt;/p&gt;';
  }
  
  } else { // If one of the data tests failed.
  echo '&lt;p&gt;&lt;font color="red" size="+1"&gt;Please check all mandatory fields are complete and try again.
  &lt;/font&gt;&lt;/p&gt;';
  }
  
  mysql_close(); // Close the database connection.
  
  } // End of the main Submit conditional.
  ?&gt;                          
  
  &lt;form action="logsales.php" method="post"&gt;
  
  &lt;table width="520" border="0" cellspacing="3" cellpadding="2"&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;N-Club Battery No&lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;            
  &lt;select  name="npc_battery_n_code" id="npc_battery_n_code"&gt;
  &lt;option value="None" &lt;?php if (isset($_POST['npc_battery_n_code']) &amp;&amp; $_POST['npc_battery_n_code'] == 'None') 
  {echo 'selected="selected"';} ?&gt;&gt;None&lt;/option&gt;
  &lt;option value="55D23L" &lt;?php if (isset($_POST['npc_battery_n_code']) &amp;&amp; $_POST['npc_battery_n_code'] == '55D23L') 
  {echo 'selected="selected"';} ?&gt;&gt;55D23L&lt;/option&gt;
  &lt;option value="55D23R" &lt;?php if (isset($_POST['npc_battery_n_code']) &amp;&amp; $_POST['npc_battery_n_code'] == '55D23R') 
  {echo 'selected="selected"';} ?&gt;&gt;55D23R&lt;/option&gt;                                
  &lt;option value="75D23R" &lt;?php if (isset($_POST['npc_battery_n_code']) &amp;&amp; $_POST['npc_battery_n_code'] == '75D23R') 
  {echo 'selected="selected"';} ?&gt;&gt;75D23R&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;  
  
  &lt;tr&gt;
  &lt;td width="184"&gt;&lt;div align="right"&gt;Other Battery No&lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td width="323"&gt;
  &lt;select  name="npc_battery_other_code" id="npc_battery_other_code"&gt;
  &lt;option value="None"  &lt;?php if (isset($_POST['npc_battery_other_code']) &amp;&amp; $_POST['npc_battery_other_code'] == 'None') 
  {echo 'selected="selected"';} ?&gt;&gt;None&lt;/option&gt;
  &lt;option value="3"  &lt;?php if (isset($_POST['npc_battery_other_code']) &amp;&amp; $_POST['npc_battery_other_code'] == '3') 
  {echo 'selected="selected"';} ?&gt;&gt;3&lt;/option&gt;
  &lt;option value="26" &lt;?php if (isset($_POST['npc_battery_other_code']) &amp;&amp; $_POST['npc_battery_other_code'] == '26') 
  {echo 'selected="selected"';} ?&gt;&gt;26&lt;/option&gt;                                                               
  &lt;option value="29" &lt;?php if (isset($_POST['npc_battery_other_code']) &amp;&amp; $_POST['npc_battery_other_code'] == '29') 
  {echo 'selected="selected"';} ?&gt;&gt;29&lt;/option&gt;
  &lt;option value="30" &lt;?php if (isset($_POST['npc_battery_other_code']) &amp;&amp; $_POST['npc_battery_other_code'] == '30') 
  {echo 'selected="selected"';} ?&gt;&gt;30&lt;/option&gt;
  &lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Quantity &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_quantity" size="10" maxlength="10" 
  value="&lt;?php if (isset($_POST['npc_quantity'])) echo $_POST['npc_quantity']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Customer Name &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_customer_name" size="30" maxlength="30" 
  value="&lt;?php if (isset($_POST['npc_customer_name'])) echo $_POST['npc_customer_name']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Customer Rego number &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_registration_no" size="10" maxlength="7" 
  value="&lt;?php if (isset($_POST['npc_registration_no'])) echo $_POST['npc_registration_no']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;SUO Number &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_suo_no" size="20" maxlength="30" 
  value="&lt;?php if (isset($_POST['npc_suo_no'])) echo $_POST['npc_suo_no']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;A-Club ID &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_amb_club_no" size="20" maxlength="30" 
  value="&lt;?php if (isset($_POST['npc_amb_club_no'])) echo $_POST['npc_amb_club_no']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Repair Order&lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_repair_order" size="20" maxlength="30" 
  value="&lt;?php if (isset($_POST['npc_repair_order'])) echo $_POST['npc_repair_order']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Invoice Number &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_invoice_no" size="20" maxlength="30" 
  value="&lt;?php if (isset($_POST['npc_invoice_no'])) echo $_POST['npc_invoice_no']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Date of Invoice &lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="npc_entry_userdate" size="20" maxlength="10" 
  value="&lt;?php if (isset($_POST['npc_entry_userdate'])) echo $_POST['npc_entry_userdate']; ?&gt;" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;
  &lt;span class="sml_italics"&gt;MM-DD-YYYY &lt;/span&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;div align="right"&gt;Invoice copy&lt;span class="style2"&gt;*&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt; 
  &lt;input type="file" name="image"  size="30" maxlength="60" /&gt; &lt;br /&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/p&gt;&lt;input type="hidden" name="submitted" value="TRUE" /&gt;
  &amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/form&gt;
  
  &lt;p&gt;footer&lt;/p&gt;
  
  &lt;?php
  include ('./includes/footer.html');
  ?&gt; 
  </code></pre>