错误:“注意:未定义索引" [英] Errors: "Notice: Undefined index"

查看:86
本文介绍了错误:“注意:未定义索引"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  [Errors][1]

我发布了我编辑过的代码,但出现了一些我不明白的新错误

I posted the code that I edited, and there are new errors w/c i didn't understand

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

Notice: Undefined index: product_brand in C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 152

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

Notice: Undefined index: product_price in C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 153

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

Notice: Undefined index: product_images in C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 158

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

Notice: Undefined index: product_images in C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 159

<!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>";

 }  
 }




 ?>

推荐答案

您将提交按钮名称定义为insert_post".但是在 if 条件下,您使用另一个名称 (if(isset($_POST['insert_product']))).更改名称.

You define your submit button name as "insert_post". But in if condition you take another name (if(isset($_POST['insert_product']))). Change the name.

这篇关于错误:“注意:未定义索引"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆