Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Error testing locally; works fine on remote server

LEGEND ,
Jun 10, 2006 Jun 10, 2006

Copy link to clipboard

Copied

I was about to post that I'd hit an error when trying to create a
conditional region in DW 8 with ASP, CF & PHP: Training from the Source.
Rather than paste the non-PHP code, I uploaded the page to my remote server.
When I browsed to the link, the error wasn't there.

I inserted the code for the conditional region just before the opening
<form> tag, as the book instructed (Lesson 6).

<?
if ($_GET['error'] == "notnumeric")
{
echo "<p>*** Error! One or more fields was left blank or contained a
non-numeric character.</p>";
}
?>

When I preview locally, the page appears correctly, but with the following
message before the form:

Notice: Undefined index: error in C:\Program Files\Apache
Group\Apache2\htdocs\newland\Lesson06\Start\newland-php\tourprice.php on
line 27

Line 27 is where the "if" statement starts.

On my remote server, everything works as it should:

http://www.feathertheweb.com/newland/Lesson06/Start/newland-php/tourprice.php

Any help is appreciated.

Thanks,

--
Heather



TOPICS
Server side applications

Views

443
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2006 Jun 10, 2006

Copy link to clipboard

Copied

Heather wrote:
> I inserted the code for the conditional region just before the opening
> <form> tag, as the book instructed (Lesson 6).
>
> <?
> if ($_GET['error'] == "notnumeric")
>
> When I preview locally, the page appears correctly, but with the following
> message before the form:
>
> Notice: Undefined index: error in C:\Program Files\Apache

It's badly written code. It should be

if (isset($_GET['error']) && $_GET['error'] == "notnumeric")

> On my remote server, everything works as it should:

That's because your remote server has been configured to suppress PHP
notices.

PHP notices alert you to non-fatal mistakes in coding. A lot of people
just ignore them, but it's a sloppy habit to get into, because it can
lay your scripts open to attack. Before testing the value of a variable,
you should always use isset() to check that the variable has been
defined in the first place.

http://www.php.net/manual/en/function.isset.php

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2006 Jun 10, 2006

Copy link to clipboard

Copied

Ah, I see. Thanks again for your help, David.

--
Heather


"David Powers" <david@example.com> wrote in message
news:e6fhjf$mc5$1@forums.macromedia.com...
> Heather wrote:
>> I inserted the code for the conditional region just before the opening
>> <form> tag, as the book instructed (Lesson 6).
>>
>> <?
>> if ($_GET['error'] == "notnumeric")
>>
>> When I preview locally, the page appears correctly, but with the
>> following message before the form:
>>
>> Notice: Undefined index: error in C:\Program Files\Apache
>
> It's badly written code. It should be
>
> if (isset($_GET['error']) && $_GET['error'] == "notnumeric")
>
>> On my remote server, everything works as it should:
>
> That's because your remote server has been configured to suppress PHP
> notices.
>
> PHP notices alert you to non-fatal mistakes in coding. A lot of people
> just ignore them, but it's a sloppy habit to get into, because it can lay
> your scripts open to attack. Before testing the value of a variable, you
> should always use isset() to check that the variable has been defined in
> the first place.
>
> http://www.php.net/manual/en/function.isset.php
>
> --
> David Powers
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "Foundation PHP 5 for Flash" (friends of ED)
> http://foundationphp.com/


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2006 Jun 10, 2006

Copy link to clipboard

Copied

So, I changed the code you had provided and that worked. Now, I've tested
the form and when I click "submit," I get this:

Notice: Undefined index: nmChildren in C:\Program Files\Apache
Group\Apache2\htdocs\newland\Lesson06\Start\newland-php\tourprice_processor.php
on line 2

Warning: Cannot modify header information - headers already sent by (output
started at C:\Program Files\Apache
Group\Apache2\htdocs\newland\Lesson06\Start\newland-php\tourprice_processor.php:2)
in C:\Program Files\Apache
Group\Apache2\htdocs\newland\Lesson06\Start\newland-php\tourprice_processor.php
on line 4

I'm guessing it's related to the change I made in tourprice.php. I tried to
figure out what needed to be changed in tourprice_processor.php based on
that change, but I'm still pretty new at this and really wasn't sure.

Below is the code from tourprice_processor.php:

<?php
if (is_numeric($_POST['numAdults']) == false or
is_numeric($_POST['nmChildren']) == false)
{
header("Location: tourprice.php?error=notnumeric");
exit;
}
?>

<?php
$numAdult = $_POST['numAdults'];
$numChild = $_POST['numChildren'];
$basePrice = $_POST['tourName'];
$tourPrice = ($numAdult * $basePrice) + ($numChild * $basePrice);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<title>Newland Tours: Tour Price Calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/newland.css" rel="stylesheet" type="text/css" /></head>

<body>
<a href="#top"><img src="images/spacer.gif" alt="Skip to main page content"
width="1" height="1" border="0" align="left" /></a>
<table width="750" border="0" cellpadding="3" cellspacing="0">
<tr>
<td><img src="images/banner_left.gif" width="451" height="68" alt="Newland
Tours Banner, Left." /></td>
<td width="280"><img src="images/banner_right.jpg" width="276" height="68"
alt="Newland Tour Banner, Right." /></td>
</tr>
<tr>
<td><img src="images/navbar.gif" name="navbar" width="450" height="20"
border="0" usemap="#navbarMap" alt="Navigation Bar." /></td>
<td><img name="copyright_bar" src="images/copyright_bar.gif" width="272"
height="20" border="0" alt="Copyright 2006 Newland Tours." /></td>
</tr>
<tr>
<td colspan="2">
<h1><br />
<a name="top" id="top"></a>Tour Price Calculator</h1>
<p>The estimated cost of your tour is <strong><?php echo
'$'.number_format($tourPrice, 2); ?></strong>.</p>
<p>Prices include hotel, accommodation, and travel expenses during the
tour. They
do not include airfare to the starting destination.</p>
<p><a href="tourprice.php">Calculate</a> another tour.</p>
<p><a href="contact.php">Contact</a> one of our qualified agents.</p>
</td>
</tr>
</table>

<br />


<map name="navbarMap" id="navbarMap">
<area shape="rect" coords="1,0,62,20" href="index.php" alt="Home" />
<area shape="rect" coords="71,0,117,20" href="about.php" alt="About" />
<area shape="rect" coords="129,0,196,20" href="tours.php" alt="Find Tours"
/>
<area shape="rect" coords="209,0,311,20" href="profiles.php" alt="Country
Profiles" />
<area shape="rect" coords="327,0,434,20" href="contact.php" alt="Contact An
Agent" />
</map>
</body>
</html>

--
Heather


"David Powers" <david@example.com> wrote in message
news:e6fhjf$mc5$1@forums.macromedia.com...
> Heather wrote:
>> I inserted the code for the conditional region just before the opening
>> <form> tag, as the book instructed (Lesson 6).
>>
>> <?
>> if ($_GET['error'] == "notnumeric")
>>
>> When I preview locally, the page appears correctly, but with the
>> following message before the form:
>>
>> Notice: Undefined index: error in C:\Program Files\Apache
>
> It's badly written code. It should be
>
> if (isset($_GET['error']) && $_GET['error'] == "notnumeric")
>
>> On my remote server, everything works as it should:
>
> That's because your remote server has been configured to suppress PHP
> notices.
>
> PHP notices alert you to non-fatal mistakes in coding. A lot of people
> just ignore them, but it's a sloppy habit to get into, because it can lay
> your scripts open to attack. Before testing the value of a variable, you
> should always use isset() to check that the variable has been defined in
> the first place.
>
> http://www.php.net/manual/en/function.isset.php
>
> --
> David Powers
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "Foundation PHP 5 for Flash" (friends of ED)
> http://foundationphp.com/


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2006 Jun 11, 2006

Copy link to clipboard

Copied

Heather wrote:
> So, I changed the code you had provided and that worked. Now, I've tested
> the form and when I click "submit," I get this:
>
> Notice: Undefined index: nmChildren in C:\Program Files\Apache
> Group\Apache2\htdocs\newland\Lesson06\Start\newland-php\tourprice_processor.php
> on line 2

That's where PHP Notices are very useful. It tells you that nmChildren
is undefined. Look at your code again:

> is_numeric($_POST['nmChildren']) == false)

> $numChild = $_POST['numChildren'];

The first one is $_POST['nmChildren']; the second is
$_POST['numChildren']. You have misspelled the first one.

The headers already sent error is caused by the display of the Notice.
Once you have corrected the spelling, it should go away.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2006 Jun 11, 2006

Copy link to clipboard

Copied

LATEST
> The first one is $_POST['nmChildren']; the second is
> $_POST['numChildren']. You have misspelled the first one.

Whoops.

All fixed and working now. 🙂 Thanks again!

--
Heather


"David Powers" <david@example.com> wrote in message
news:e6gi6t$q8t$1@forums.macromedia.com...
> Heather wrote:
>> So, I changed the code you had provided and that worked. Now, I've
>> tested the form and when I click "submit," I get this:
>>
>> Notice: Undefined index: nmChildren in C:\Program Files\Apache
>> Group\Apache2\htdocs\newland\Lesson06\Start\newland-php\tourprice_processor.php
>> on line 2
>
> That's where PHP Notices are very useful. It tells you that nmChildren is
> undefined. Look at your code again:
>
>> is_numeric($_POST['nmChildren']) == false)
>
>> $numChild = $_POST['numChildren'];
>

>
> The headers already sent error is caused by the display of the Notice.
> Once you have corrected the spelling, it should go away.
>
> --
> David Powers
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "Foundation PHP 5 for Flash" (friends of ED)
> http://foundationphp.com/


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines