title: Upload image into database using php
body: <p>i am trying to upload image into database using php, i got an error message saying Undefined index: horse_image</p>
  
  <p>here is the form code:</p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data"action="newhorse.php"
  OnSubmit="return VerifyDataEntry(this)"&gt;  
  &lt;p&gt;Please type the horse details below 
  &lt;p&gt;Horse Id: &lt;input type="text" name="horse_id"&gt;  
  &lt;p&gt;Horse name: &lt;input type="text" name="horse_name"&gt;
  &lt;p&gt;Horse Gender: &lt;span id="spryradio1"&gt;
  &lt;label&gt;
    &lt;input type="radio" name="horse_gender" value="m" id="horse_gender_0" /&gt;
    Male&lt;/label&gt;
  
  &lt;label&gt;
    &lt;input type="radio" name="horse_gender" value="f" id="horse_gender_1" /&gt;
    Female&lt;/label&gt;
  &lt;br /&gt;
  &lt;span class="radioRequiredMsg"&gt;Please make a selection.&lt;/span&gt;&lt;/span&gt;
  
  &lt;p&gt;Horse Height: &lt;input type="text" name="horse_height"&gt;
  &lt;?php
    if (!isset($_FILES["horse_image"]["tmp_name"]))
    {
   ?&gt;
  
          &lt;p&gt;Select an image to upload:
            &lt;input type="file" size="50" name="horse_image"&gt;
  
  
  &lt;?php
    }
    else
    {
      $upfile = "horse_images/".$_FILES["horse_image"]["name"];
  
      $imgsize=getimagesize($_FILES["horse_image"]["tmp_name"]);
  
      if(!move_uploaded_file($_FILES["horse_image"]
        ["tmp_name"],$upfile))
      {
        echo "ERROR: Could Not Move File into Directory";
      }
  
    }
   ?&gt;
  &lt;p&gt;&lt;span id="spryselect1"&gt;
  &lt;label for="horse_breed"&gt;Horse Breed: &lt;/label&gt;
  &lt;select name="horse_breed" id="horse_breed"&gt;
    &lt;option value="0" selected="selected"&gt;please select&lt;/option&gt;
    &lt;option value="13"&gt;american&lt;/option&gt;
    &lt;option value="14"&gt;asian&lt;/option&gt;
    &lt;option value="11"&gt;australian&lt;/option&gt;
    &lt;option value="12"&gt;brazilian&lt;/option&gt;
    &lt;option value="15"&gt;europian&lt;/option&gt;
  &lt;/select&gt;
  &lt;?php
    include("connection.php"); 
       $conn = oci_connect($UName,$PWord,$DB);
    $query = "Select * FROM skill ORDER BY SKILL_DESC";
      $stmt = oci_parse($conn,$query);
    oci_execute($stmt);
  ?&gt;
  &lt;p&gt;Select horse skill(s)
  &lt;p&gt;
  &lt;table border="2" cellpadding="4"&gt;
    &lt;tr&gt;
      &lt;th&gt;Skill Id&lt;/th&gt;
      &lt;th&gt;Skill Name&lt;/th&gt;
      &lt;th&gt;Add?&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php 
    while ($skills = oci_fetch_array ($stmt))
    {
  ?&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $skills["SKILL_ID"]; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $skills["SKILL_DESC"]; ?&gt;&lt;/td&gt;
        &lt;td align="center"&gt;
  
  &lt;input type="checkbox" name="check[]" value="&lt;?php echo $skills["SKILL_ID"]; ?&gt;"&gt;
  
        &lt;/td&gt;
      &lt;/tr&gt;
  &lt;?php
    }
  ?&gt;
  
  &lt;/table&gt;
  &lt;p&gt;&lt;input type="Submit" Value="Submit"&gt;  &lt;input type="Reset" Value="Clear Form Fields"&gt;  
  &lt;/form&gt;
  </code></pre>
  
  <p>here is the code in newhorse.php</p>
  
  <pre><code>&lt;?php 
  $horse_id = $_POST["horse_id"]; 
  $horse_name = $_POST["horse_name"]; 
  $horse_gender = $_POST["horse_gender"];
  $horse_height = $_POST["horse_height"];
  $horse_image = $_POST["horse_image"];
  $horse_breed = $_POST["horse_breed"];
  ?&gt; 
      &lt;table border="0"&gt;  
      &lt;tr&gt;  
      &lt;td&gt;Horse Id: &lt;?php echo $_POST["horse_id"]; ?&gt;&lt;/td&gt;  
      &lt;/tr&gt;  
      &lt;tr&gt;  
      &lt;td&gt;Horse Name: &lt;?php echo $_POST["horse_name"]?&gt; &lt;/td&gt; 
      &lt;/tr&gt;  
      &lt;tr&gt;  
      &lt;td&gt;Horse Gender: &lt;?php echo $_POST["horse_gender"] ?&gt;&lt;/td&gt;  
      &lt;/tr&gt;  
      &lt;tr&gt;  
      &lt;td&gt;Horse Height: &lt;?php echo $_POST["horse_height"] ?&gt;&lt;/td&gt;  
      &lt;/tr&gt;
      &lt;tr&gt;  
      &lt;td&gt;Horse Image: &lt;?php echo $_POST["horse_image"]
       ?&gt;&lt;/td&gt;  
      &lt;/tr&gt;
      &lt;tr&gt;  
      &lt;td&gt;Horse Breed: &lt;?php echo $_POST["horse_breed"] ?&gt;&lt;/td&gt;  
      &lt;/tr&gt;
      &lt;/table&gt; 
  
  
  
  
      &lt;?php
  
            include("connection.php");
            $conn = oci_connect($UName,$PWord,$DB);
  
            $query="INSERT INTO horse (horse_id, horse_name,horse_gender,horse_height,horse_image,horse_breed) VALUES('$_POST[horse_id]','$_POST[horse_name]','$_POST[horse_gender]','$_POST[horse_height]','$_POST[horse_image]','$_POST[horse_breed]')";
  
            $stmt = oci_parse($conn,$query);
            oci_execute($stmt); 
  
  
      ?&gt;
  </code></pre>