RE: [PHP] undefined index
| From: | Kim Madsen | Date: | Fri, 17 Jun 2005 07:46:07 +0000 |
| Subject: | RE: [PHP] undefined index | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-217120@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ross [mailto:ross@aztechost.com]
> Sent: Thursday, June 16, 2005 8:51 PM
> if ($quantity == 0){
>
> }
> else {
>
> $pieces = explode(" ", $quantity);
> $formatted_price = sprintf('%0.2f', $pricecode);
> echo "<table width=\"240\" border=\"0\"
> cellpadding=\"2\"
> cellspacing=\"5\"><tr><td valign=\"top\"
> align=\"right\"
> width=\"40\">$pieces[0]</td><td align=\"left\"
> width=\"60\"></td><td
> align=\"left\" width=\"200\">$pieces[1] $pieces[2] $pieces[3]
> $pieces[4]</td><td valign=\"top\" align=\"left\"
> width=\"80\">$formatted_price</td></tr></table>";
>
> }
> }
>
> The trouble is I get a NOTICE that tells me the indexes 1 to 4 have
not
> been defined. how do I do this.
Probably because $quantity IS 0, then the vars used in the else {} is
never set, but still in the script.
Try setting these before the if statement:
$pieces = array();
$formatted_price = 0;
$pricecode = 0; // this one is never set? Or set earlier in the script?
--
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen
Systemudvikler/Systemdeveloper