$_Post error

Steven Monai stevem at SPATIALMAPPING.COM
Thu Sep 8 11:45:36 EDT 2005


On Wed, 7 Sep 2005 14:04:19 -0400, Bill Chappell <bill at POCONOGIS.COM> wrote:

>Hi, I'm new to PHP and struggling with the examples in Bill Kropla's
>"Beginning Mapserver" book, I'm not sure what is going on but I've tried
the
>example as per then book and also from my own data and I'm getting the same
>error. The script does generate a png image that looks correct but errors
>when it gets to the $_POST command.
>
>Any clues?


Yes, see below.


><?php
...
[snipped for brevity]
...
>
>// I believe the error is here but I don't know what to do about it?
>
>if (( $_POST['img_x'] and $_POST['img_y'] )
>
>            or $_POST['refresh']) {
>
>Generates a :
>
>Notice: Undefined index: img_x in
>C:\Inetpub\wwwroot\cgi-bin\Pocono\pocono.php on line 76
>
>Notice: Undefined index: refresh in
>C:\Inetpub\wwwroot\cgi-bin\Pocono\pocono.php on line 76


First of all, "Notice" messages from PHP are not really errors, they're
just "notices" of possibly incorrect or questionable coding. In this case,
it looks like the code intends to check whether the keys 'img_x'
and 'img_y' or 'refresh' are set in the $_POST superglobal array. While I
wouldn't recommend it as general practice, you can tell PHP to
suppress "Notice" messages in your script with the error_reporting()
function. Put the following line near the top of your script:


error_reporting(E_ALL ^ E_NOTICE);


A better solution is to modify the code so that PHP is happy. Try this
logically equivalent replacement for the above 'if' statement:


if ( ( (isset($_POST['img_x']) and $_POST['img_x']) and
       (isset($_POST['img_y']) and $_POST['img_y']) )
    or (isset($_POST['refresh']) and $_POST['refresh']) ) {


Or try the following, which may be closer to what the original author
intended:


if ( ( isset($_POST['img_x']) and isset($_POST['img_y']) )
    or isset($_POST['refresh']) ) {


Hope this helps,
-SM
--



More information about the mapserver-users mailing list