注意:带有“ img”的未定义索引

时间:2019-12-03 13:49:48

标签: php file

运行我的.php代码时,出现以下错误:

  

(!)注意:未定义的索引:第161行的C:\ wamp \ www \ mesprojets \ PHP \ projet_perso \ insert_product.php中的product_img1

product_img1product_img2product_img3出现一些错误。

var_dump($_POST);为空。

错误示例:

  

未定义索引:product_img1在   C:\ wamp \ www \ mesprojets \ PHP \ projet_perso \ insert_product.php

这是我正在使用的代码:

<body>

    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li class="active">
                    <i class="fa fa-dashboard"></i> Dashboard / Insérer des produits
                </li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="fa fa-money fa-fw"></i> Insérer un produit
                    </h3>
                </div>
                <div class="panel-body">
                    <form method="post" class="form-horizontal" encotype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-md-3 control-label">Titre du produit</label>
                            <div class="col-md-6">
                                <input type="text" name="product_title" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">Catégories de produit</label>
                            <div class="col-md-6">
                                <select name="product_cat" class="form-control">
                                    <option> Sélectionnez une catégorie de produits</option>

                                    <?php
                                        $get_p_cats = "SELECT * FROM product_categories";
                                        $run_p_cats = mysqli_query($con,$get_p_cats);
                                        while($row_p_cats = mysqli_fetch_array($run_p_cats)){
                                            $p_cat_id = $row_p_cats['p_cat_id'];
                                            $p_cat_title = $row_p_cats['p_cat_title'];
                                            echo "
                                                <option value='$p_cat_id'> $p_cat_title</option>

                                            ";
                                        }
                                    ?>

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label">Catégories</label>
                            <div class="col-md-6">
                                <select name="cat" class="form-control">
                                    <option> Sélectionnez une catégorie</option>

                                    <?php
                                        $get_cat = "SELECT * FROM categories";
                                        $run_cat = mysqli_query($con,$get_cat);
                                        while($row_cat = mysqli_fetch_array($run_cat)){
                                            $cat_id = $row_cat['cat_id'];
                                            $cat_title = $row_cat['cat_title'];
                                            echo " <option value='$cat_id'> $cat_title</option> ";
                                        }
                                    ?>

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> Image1 du produit</label>
                            <div class="col-md-6">
                                <input type="file" name="product_img1" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> Image2 du produit </label>
                            <div class="col-md-6">
                                <input type="file" name="product_img2" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> Image3 du produit </label>
                            <div class="col-md-6">
                                <input type="file" name="product_img3" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> Prix du produit </label>
                            <div class="col-md-6">
                                <input type="text" name="product_price" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> Mots clés du produit </label>
                            <div class="col-md-6">
                                <input type="text" name="product_keywords" class="form-control" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> Description du produit </label>
                            <div class="col-md-6">
                                <textarea name="product_desc" cols="20" rows="5" class="form-control" required></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label"> </label>
                            <div class="col-md-6">
                                <input type="submit" name="submit" value="Inserez un produit" class="btn btn-primary form-control">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div> 




    <?php
    if(isset($_POST['submit'])){
        $product_title = $_POST['product_title'];
        $product_cat = $_POST['product_cat'];
        $cat = $_POST['cat'];
        $product_price = $_POST['product_price'];
        $product_keywords = $_POST['product_keywords'];
        $product_desc = $_POST['product_desc'];
        $product_img1 = $_FILES['product_img1']['name'];
        $product_img2 = $_FILES['product_img2']['name'];
        $product_img3 = $_FILES['product_img3']['name'];
        $temp_name1 = $_FILES['product_img1']['tmp_name'];
        $temp_name2 = $_FILES['product_img2']['tmp_name'];
        $temp_name3 = $_FILES['product_img3']['tmp_name'];
        move_uploaded_file($temp_name1,"product_images/$product_img1");
        move_uploaded_file($temp_name2,"product_images/$product_img2");
        move_uploaded_file($temp_name3,"product_images/$product_img3");

        $insert_product = "INSERT INTO products
        (p_cat_id,cat_id,date,product_title,product_img1,product_img2,product_img3,product_prie,product_keywords,product_desc) VALUES ('$product_cat','$cat',NOW(),'$product_title','$product_img1','$product_img2','$product_img3','$product_price','$product_keywords','$product_desc')";

      $run_product = mysqli_query($con,$insert_product);
      if($run_product){
        echo "<script>alert('Produit ajouté avec succès')</script>";
        echo "<script>window.open('insert_product.php','_self')</script>";
      }
    }
    ?>

0 个答案:

没有答案