错误:“注意:未定义的索引”

时间:2017-06-17 04:52:27

标签: php mysql

<!DOCTYPE>

<?php

include("includes/db.php");


?>
<html>
<head>
    <title>Inserting Product</title>


    <script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>

</head> 
<body bgcolor="red">

<form action="insert_product.php"method="post"enctype= 
"multipart/form/data">
    <table align="center" width="700" border="5" bgcolor="white" >


    <tr>

        <td colspan="8"><h2 style="text-align:center;font-family:Arial;"> 
 Insert New Post Here</h2></td>

    </tr>


    <tr>
        <td align="right"><b>Product Name:</b></td>
        <td><input type="text" name= "product_name"  size="60" required />
 </td>

    </tr>

    <tr>
        <td align="right"><b>Product Category:</b></td>
        <td>

        <select name="product_cat" required>
            <option>Select Category</option>

            <?php

            global $con;
 $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 "<li><option>$cat_title</option></li>";

 }          
            ?>
            </select>

        </td>

    </tr>

    <tr>
        <td align="right"><b>Product Brand:</b></td>
        <td>

        <select name="product_brand" required>
            <option>Select Brand</option>

            <?php

            global $con;
 $get_brands = "select * from brands";


 $run_brands = mysqli_query($con, $get_brands);

 while ($row_brands=mysqli_fetch_array($run_brands)){

    $brands_id= $row_brands['brand_id'];
    $brands_title= $row_brands['brand_title'];

 echo "<li><option>$brands_title</option></li>";

 }

            ?>
            </select>





        </td>

    </tr>

    <tr>
        <td align="right"><b>Product Image:</b></td>
        <td><input type="file" name= "product_image" required /></td>

    </tr>

    <tr>
        <td align="right"><b>Product Price:</b></td>
        <td><input type="currency" name= "product_price" required/></td>

    </tr>

    <tr>
        <td align="right"><b>Product Description:</b></td>
        <td><textarea name="product_desc" cols="20" rows="10"></textarea>
    </td>

    </tr>

    <tr>
        <td align="right"><b>Product Keywords:</b></td>
        <td><input type="text" name= "product_keywords" size="50" 
    required /></td>

    </tr>



<tr align="center">


<td colspan="7"><input type="Submit" name= "insert_post" value="Insert 
Product Here"/></td>

    </tr>
</table>

</body>
</html>

 <?php


   if(isset($_POST['insert_post'])){

//getting text data
$product_name = $_POST['product_name'];
$product_cat = $_POST['product_cat'];
$product_brands = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];

//getting image data
$product_image = $_FILES['product_images']['name'];
$product_image_tmp = $_FILES['product_images']['tmp_name'];

 move_uploaded_file($product_image_tmp,"products_images/$product_image");

 $insert_product = "insert into products 

(product_cat,product_brands,product_name,product_price,product_desc,
 product_img,product_keyword) values ('$product_cat','$product_brands'
 ,'$product_name','$product_price','$product_desc','$product_image'
 ,'$product_keywords')";

$run_product = mysqli_query($con,$insert_product);

if($run_product){

echo"<script>alert('Product Has been inserted')</script>";
echo"<script>window.open('insert_product.php','_self')</script>";

 }  
 }




 ?>

我发布了我编辑的代码,并且有新的错误w / c我不明白

  

注意:未定义的索引:product_brand in   第152行的C:\ xampp \ htdocs \ JGMarketing \ Admin_Area \ insert_product.php

     

注意:未定义的索引:product_price in   第153行的C:\ xampp \ htdocs \ JGMarketing \ Admin_Area \ _ insert_product.php

     

注意:未定义的索引:product_images in   第158行的C:\ xampp \ htdocs \ JGMarketing \ Admin_Area \ _ insert_product.php

     

注意:未定义的索引:product_images in   第159行的C:\ xampp \ htdocs \ JGMarketing \ Admin_Area \ _ insert_product.php

  commands.getoutput("touch /mytxt.txt")
  x="hello"
  commands.getoutput("echo x | cat >> /mytxt.txt".format(x))

3 个答案:

答案 0 :(得分:0)

您将提交按钮名称定义为&#34; insert_post&#34;。但是,如果条件你采取另一个名称(如果(isset($ _ POST [&#39; insert_product&#39;])))。更改名称。

答案 1 :(得分:-1)

  

您的查询错误:

 $insert_product="insert into products 
(product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price',','$product_desc','$product_image','$product_keywords')";
  

插入此查询:

$insert_product="insert into products 
    (product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price','$product_desc','$product_image','$product_keywords')";

答案 2 :(得分:-1)

尝试使用这样的...请确保正确检查数据库连接和表单操作。

if(isset($_POST['insert_post'])){

//getting text data from fields
 $product_name = $_POST['product_name'];
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];


//getting image from fields
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];

move_uploaded_file($product_image_tmp,"product_images/$product_image");

    $insert_product="insert into products (product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price','$product_desc','$product_image','$product_keywords')";

 $insert_pro = mysqli_query($con, $insert_product);

if($insert_pro){

echo"alert('Product Has been inserted')";

echo"window.open('insert_product.php','_self')";

}

else{
    echo "Something has gone wrong";
}

    }