Solved

PHP Notice: Undefined index

Posted on 2011-03-06
7
692 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 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