获取错误插入新数据时查询为空

时间:2016-03-12 19:05:53

标签: php

我正在编写一个脚本以将新数据插入Database,但我一直收到错误: -

  

注意:未定义的索引:priceBig in   第12行的C:\ xampp \ htdocs \ demo \ admin \ add.php

我错过了什么吗?

如何修复此错误?任何帮助都会很棒。谢谢

CREATE TABLE IF NOT EXISTS `items` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `product_code` varchar(60) NOT NULL,
  `product_name` varchar(60) NOT NULL,
  `product_desc` tinytext NOT NULL,
  `product_img_name` varchar(60),
  `price` decimal(10,2) NOT NULL,
  `price_big` decimal (10,2) ,
  `product_type` varchar(60) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `product_code` (`product_code`)
) AUTO_INCREMENT=1 ;


require("config.php");
$status = "";
if(isset($_POST['new']) && $_POST['new']==1){
    $id                 = $_REQUEST['id'];
    $product_code       = $_REQUEST['product_code'];
    $product_name       = $_REQUEST['product_name'];
    $product_desc       = $_REQUEST['product_desc'];
    $product_img_name   = $_REQUEST['product_img_name'];
    $price              = $_REQUEST['price'];
    $priceBig           = $_REQUEST['priceBig'];
    $product_type       = $_REQUEST['product_type'];
    // $submittedby     = $_SESSION["username"];
    $ins_query          = "INSERT INTO items(id, product_code, product_name, product_desc, product_img_name, price, priceBig, product_type) VALUES
        ('$id','$product_code', '$product_name', '$product_desc', '$product_img_name', '$price', '$priceBig', '$product_type')";
    mysql_query($ins_query) or die(mysql_error());
    $status = "New Record Inserted Successfully.</br></br><a href='admin.php?appetizers_Soup'>View Inserted Record</a>";
}


<form name="form" method="post" action="add.php">
    <input type="hidden" name="new" value="1" />
    <p><input type="text" name="id" placeholder="Enter ID" required /></p>
    <p><input type="text" name="product_code" placeholder="Enter Product Code" required /></p>
    <p><input type="text" name="product_name" placeholder="Enter Product Name" required /></p>
    <p><input type="text" name="product_desc" placeholder="Enter Product Description" required /></p>
    <p><input type="text" name="product_img_name" placeholder="Enter Product Image" /></p>
    <p><input type="text" name="price" placeholder="Enter Price 1" required /></p>
    <p><input type="text" name="priceBig" placeholder="Enter Price 2" /></p>
    <p><input type="text" name="product_type" placeholder="Enter Product Type" required /></p>
    <p><input name="submit" type="submit" value="Submit" /></p>
</form>

2 个答案:

答案 0 :(得分:0)

使用这种方式:

>>> x_flat = [i for sub_l in x for i in sub_l]
>>> final_list = []
>>> for number in x_flat:
        if number not in final_list:
            finalList.append(number)

答案 1 :(得分:0)

$_REQUEST['priceBig']根本没有定义。

如果写一个空字段或只是NULL表没问题,可以通过检查$_REQUEST['priceBig']是否设置或为空来解决这个问题,然后将其定义为NULL:

if(!isset($_REQUEST['priceBig'])){
    $priceBig = NULL;
}else{
    $priceBig = $_REQUEST['priceBig'];
}