• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 715
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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