?
Solved

PHP Notice: Undefined index

Posted on 2011-03-06
7
Medium Priority
?
704 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 500 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 1000 total points
ID: 35047382
Yes,
<?php error_reporting(E_ALL ^ E_NOTICE);?>
is ok.
0
 
LVL 2

Assisted Solution

by:adeelshahid
adeelshahid earned 500 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.
Suggested Courses

743 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