问题描述:

I am writing a script to insert a new data into Database, but I keep getting an error:-

Notice: Undefined index: priceBig in

C:\xampp\htdocs\demo\admin\add.php on line 12

Am I missing something?

How can I fix this error? Any help would be great. Thank you

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>

网友答案:

$_REQUEST['priceBig'] simply is not defined.

If it's no problem to write a empty field or just NULL to your table you could resolve that by checking if $_REQUEST['priceBig'] is set or is empty and then define it as NULL:

if(!isset($_REQUEST['priceBig'])){
    $priceBig = NULL;
}else{
    $priceBig = $_REQUEST['priceBig'];
}
网友答案:

Use this way:

 if(isset($_REQUEST['priceBig'])){
       $priceBig = $_REQUEST['priceBig'];
 } else{
        $priceBig = "";
 }
相关阅读:
Top