0

i am trying to upload image into database using php, i got an error message saying Undefined index: horse_image

here is the form code:

<form method="post" enctype="multipart/form-data"action="newhorse.php"
OnSubmit="return VerifyDataEntry(this)">  
<p>Please type the horse details below 
<p>Horse Id: <input type="text" name="horse_id">  
<p>Horse name: <input type="text" name="horse_name">
<p>Horse Gender: <span id="spryradio1">
<label>
  <input type="radio" name="horse_gender" value="m" id="horse_gender_0" />
  Male</label>

<label>
  <input type="radio" name="horse_gender" value="f" id="horse_gender_1" />
  Female</label>
<br />
<span class="radioRequiredMsg">Please make a selection.</span></span>

<p>Horse Height: <input type="text" name="horse_height">
<?php
  if (!isset($_FILES["horse_image"]["tmp_name"]))
  {
 ?>

        <p>Select an image to upload:
          <input type="file" size="50" name="horse_image">


<?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";
    }

  }
 ?>
<p><span id="spryselect1">
<label for="horse_breed">Horse Breed: </label>
<select name="horse_breed" id="horse_breed">
  <option value="0" selected="selected">please select</option>
  <option value="13">american</option>
  <option value="14">asian</option>
  <option value="11">australian</option>
  <option value="12">brazilian</option>
  <option value="15">europian</option>
</select>
<?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);
?>
<p>Select horse skill(s)
<p>
<table border="2" cellpadding="4">
  <tr>
    <th>Skill Id</th>
    <th>Skill Name</th>
    <th>Add?</th>
  </tr>
  <?php 
  while ($skills = oci_fetch_array ($stmt))
  {
?>
    <tr>
      <td><?php echo $skills["SKILL_ID"]; ?></td>
      <td><?php echo $skills["SKILL_DESC"]; ?></td>
      <td align="center">

<input type="checkbox" name="check[]" value="<?php echo $skills["SKILL_ID"]; ?>">

      </td>
    </tr>
<?php
  }
?>

</table>
<p><input type="Submit" Value="Submit">  <input type="Reset" Value="Clear Form Fields">  
</form>

here is the code in newhorse.php

<?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"];
?> 
    <table border="0">  
    <tr>  
    <td>Horse Id: <?php echo $_POST["horse_id"]; ?></td>  
    </tr>  
    <tr>  
    <td>Horse Name: <?php echo $_POST["horse_name"]?> </td> 
    </tr>  
    <tr>  
    <td>Horse Gender: <?php echo $_POST["horse_gender"] ?></td>  
    </tr>  
    <tr>  
    <td>Horse Height: <?php echo $_POST["horse_height"] ?></td>  
    </tr>
    <tr>  
    <td>Horse Image: <?php echo $_POST["horse_image"]
     ?></td>  
    </tr>
    <tr>  
    <td>Horse Breed: <?php echo $_POST["horse_breed"] ?></td>  
    </tr>
    </table> 




    <?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); 


    ?>
2
  • is this code giving problem in "if (!isset($_FILES["horse_image"]["tmp_name"]))" ?????? Commented Oct 6, 2010 at 6:07
  • 1
    sigh kids .. images in the database WILL create problems sooner or later. Commented Oct 6, 2010 at 9:22

3 Answers 3

1

You dont have $_POST['horse_image']

Use $_FILE['horse_image']

http://www.w3schools.com/PHP/php_file_upload.asp

Sign up to request clarification or add additional context in comments.

Comments

0

Uploaded images is not placed in the $_POST array. Read the documentation on file uploads

Comments

0

There you go

form page :

<form enctype="multipart/form-data" action="insert_image.php" method="post" name="changer">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>

insert to database page :

<?php

  include 'conf.php';

  if ($_FILES["image"]["error"] > 0)
  {
     echo "<font size = '5'><font color=\"#e31919\">Error: NO CHOSEN FILE <br />";
     echo"<p><font size = '5'><font color=\"#e31919\">INSERT TO DATABASE FAILED";
   }
   else
   {
     move_uploaded_file($_FILES["image"]["tmp_name"],"images/" . $_FILES["image"]["name"]);
     echo"<font size = '5'><font color=\"#0CF44A\">SAVED<br>";

     $file="images/".$_FILES["image"]["name"];
     $sql="INSERT INTO eikones (auxon, path) VALUES ('','$file')";

     if (!mysql_query($sql))
     {
        die('Error: ' . mysql_error());
     }
     echo "<font size = '5'><font color=\"#0CF44A\">SAVED TO DATABASE";

   }

   mysql_close();

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.