2010-10-06 7 views
0

je suis en train de télécharger l'image dans la base de données en utilisant php, j'ai reçu un message d'erreur indiquant Undefined index: horse_imageUpload image dans la base de données en utilisant php

ici est le code du formulaire:

<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> 

ici est le code dans 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); 


    ?> 
+0

est ce code donne problème dans "if (isset ($ _ FILES! [" Horse_image "] [" tmp_name "]))" ?????? – PHP

+1

* sigh * kids .. images dans la base de données vont créer des problèmes tôt ou tard. –

Répondre

0

Les images téléchargées ne sont pas placées dans le tableau $ _POST. Lisez la documentation sur file uploads

0

Il vous allez page du formulaire

:

<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 à la page de base de données:

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

?> 
Questions connexes