• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

PHP Notice: Undefined index

Okay, I have the following:
<?php
$rqty = $_POST['rqty'];
$unitprice = $_POST['iprice'];
$rtotal = $rqty*$unitprice;
echo $rtotal;?>

I get the error however:

 PHP Notice: Undefined index: iprice

Not sure what this means as $rtotal is displaying and is correct.
0
jonofat
Asked:
jonofat
4 Solutions
 
Lukasz ChmielewskiCommented:
This is just a notice, not an error.
0
 
Lukasz ChmielewskiCommented:
0
 
jonofatAuthor Commented:
How do I get rid of it cos the page isn't going to the next page as it is meant to, it just shows that notice and stays there.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jonofatAuthor Commented:
never mind, I read the url you sent me. I used <?php error_reporting(E_ALL ^ E_NOTICE);?>

Is that okay?
0
 
nickswanjanCommented:
This is a notice that you tried to assign a value that was not set (not passed in by your form). While it does not abort execution, it might indicate an error, for example maybe you intended to POST 'unitprice' instead of 'iprice'?

In your case, it will make $rtotal = 0.

If you want to clean up the notice, you can check if the value is set before you try to use it, and default it to 0 if it is not set:

<?php

if ( isset($_POST['rqty']) ) {
  $rqty = $_POST['rqty'];
} else {
  $rqty = 0;
}

if ( isset($_POST['iprice']) ) {
  $unitprice = $_POST['iprice'];
} else {
  $unitprice = 0;
}

$rtotal = $rqty*$unitprice;
echo $rtotal;
?>
0
 
Lukasz ChmielewskiCommented:
Yes,
<?php error_reporting(E_ALL ^ E_NOTICE);?>
is ok.
0
 
adeelshahidCommented:
enclose the snippet of your code inside,

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


YOUR CODE SNIPPET HERE, that should fix your issue.

}
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now