0

I'm making a web page that can send data from inputs to my database it was working untill I decided to have a file input to send an image to my database I've read lots of articles and questions but nothing works Please Can you help me !!!

*Notice: Undefined index: image in C:\wamp3.1\www\Location\ajouter.php on line 65

Notice: Undefined index: image in C:\wamp3.1\www\Location\ajouter.php on line 98*

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="style.css">

</head>
<?php
        include('connexion.php');?>
<body>
    <div class="container">
    <form method="post" action="" enctype="multipart/form-data">
        <div class="t1">
        <div class="d1"><table class="table-hover">
            <tr><th>Titre </th><td>:</td><td><input name="titre" type="text"></td></tr>
            <tr><th>Réference </th><td>:</td><td><input name="reference" type="text"></td></tr>
            <tr><th>Prix </th><td>:</td><td><input name="prix" type="text"></td></tr>
            <tr><th>Adresse </th><td>:</td><td><input name="adresse" type="text"></td></tr>
            <tr><th>Nombre de pieces </th><td>:</td><td><input name="nombrePieces" type="text"></td></tr>
            <tr><th>Surface </th><td>:</td><td><input name="surface" type="text"></td></tr></table>
        </div><!--d1-->

        <div class="d2"><table class="table-hover">
            <tr><th>Garage </th><td>:</td><td><input name="garage" type="text"></td></tr>
            <tr><th>Type de transaction </th><td>:</td><td><input name="typeTransaction" type="text"></td></tr>
            <tr><th>Etat du Bien </th><td>:</td><td><input name="etat" type="text"></td></tr>
            <tr><th>Salle de bains </th><td>:</td><td><input name="salleBains" type="text"></td></tr>
            <tr><th>Sorties/étage </th><td>:</td><td><input name="sorties" type="text"></td></tr>
            <tr><th>Terrasse </th><td>:</td><td><input name="terrasse" type="text"></td></tr></table>
        </div><!--d2-->
        <div class="d3"><table class="table-hover">
            <tr><th>Type de bien </th><td>:</td><td><input name="typeBien" type="text"></td></tr>
            <tr><th>Meublé </th><td>:</td><td><input name="meuble" type="text"></td></tr>
            <tr><th>Chambres </th><td>:</td><td><input name="chambres" type="text"></td></tr>
            <tr><th>Espaces Habitable </th><td>:</td><td><input name="espaceHabitable" type="text"></td></tr>
            <tr><th>Ascenseur </th><td>:</td><td><input name="ascenseur" type="text"></td></tr></table>
        </div><!--d3-->
        </div><!--t1-->
        <div class="t2"><table class="table-hover">
            <tr class="t2"><th class="t2">Description:</th></tr>
            <tr><td class="desc" width="100%"><textarea name="description"></textarea></td></tr>
            </tr>
            <tr class="t2"><th class="t2">Localisation du bien :</th></tr>
            <tr class="t2"><td class="t2"><input name="longitude" type="text"></td></tr>
            <tr class="t2"><td class="t2"><input name="latitude"  type="text"></td></tr>
            <tr><th>Photo</th><td>:</td><td><input type="file" name="fichier" class="btn btn-md btn-success"></td></tr>
            </table>
        </div><!--t1-->


                     <tr><th><button name="valider" class="btn1">Valider</button></th>
                 <th><button name="annuler" class="btn2">Annuler</button></th></tr>

        </table></center>
    </form></div><!--container-->

</body>
<?php 

$msg = "";
if (isset($_POST['valider'])) { 
    //the following is line 65 
    $image = $_FILES['image']['name'];
    $target = "images/".basename($image);



$query="insert into local
                    (reference,titre,image,prix,adresse,nombrePieces,surface,garage,typeTransaction,etat,salleBains,sorties,terrasse,typeBien,meuble,chambres,espaceHabitable,ascenseur,description,longitude,latitude)
                     values
                     (
                    '$_POST[reference]',
                    '$_POST[titre]',
                    '$image',
                    $_POST[prix],
                    '$_POST[adresse]',
                     $_POST[nombrePieces],
                     $_POST[surface],
                    '$_POST[garage]' ,
                    '$_POST[typeTransaction]',
                    '$_POST[etat]',
                     $_POST[salleBains] ,
                     $_POST[sorties] ,
                    '$_POST[terrasse]' ,
                    '$_POST[typeBien]',
                    '$_POST[meuble]' ,
                     $_POST[chambres] ,
                     $_POST[espaceHabitable] ,
                    '$_POST[ascenseur]' ,
                    '$_POST[description]' ,
                    '$_POST[longitude]' ,
                    '$_POST[latitude]'
                    )
                     "; 
                     @mysqli_query($link,$query);
                     //the following is line 98 
                    if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
                    $msg = "Image uploaded successfully";
                    }else{
                        $msg = "Failed to upload image";
                    }
  } 




?>


</html>
Pierre
  • 643
  • 1
  • 7
  • 14
Kyu Wiam
  • 1
  • 1

0 Answers0