Solved

PHP Notice: Undefined index

Posted on 2011-03-06
7
696 Views
Last Modified: 2012-05-11
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
Comment
Question by:jonofat
7 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35046938
This is just a notice, not an error.
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 250 total points
ID: 35046940
0
 

Author Comment

by:jonofat
ID: 35046952
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.

 

Author Comment

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

Is that okay?
0
 
LVL 3

Assisted Solution

by:nickswanjan
nickswanjan earned 125 total points
ID: 35047002
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
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 250 total points
ID: 35047382
Yes,
<?php error_reporting(E_ALL ^ E_NOTICE);?>
is ok.
0
 
LVL 2

Assisted Solution

by:adeelshahid
adeelshahid earned 125 total points
ID: 35056979
enclose the snippet of your code inside,

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


YOUR CODE SNIPPET HERE, that should fix your issue.

}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question