Undefine index error
am 04.09.2007 23:49:12 von jjm0926
I've got a contact form with a submit button where users have to enter
their support information. Some fields are required some are not.
When I test out the form if I leave everything blank I get these two
undefined index error :
Notice: Undefined index: CurrentCustomer in E:\WebSites\mysite\www
\contactus.php on line 9
Notice: Undefined index: ContactMethod in E:\WebSites\mysite\www
\contactus.php on line 19
If I fill out at least the required fields everything is fine.
Here's what the code looks like:
if (isset($_POST["Submit"])) // Trigger
{
// Email Request
$to = "support@myisp.com";
$subject = "Here Is My Contact Information";
$email = $_POST['Email'];
$message = "";
if isset($_POST['CurrentCustomer']) {
$message = $message."Current Customer: ".
$_POST['CurrentCustomer']."\n";
}
if isset($_POST['Name']) {
$message = $message."Name: ".$_POST['Name']."\n";
}
if isset($_POST['CoName']) {
$message = $message."Company Name: ".$_POST['CoName']."\n";
}
if isset($_POST['Phone']) {
$message = $message."Phone Number: ".$_POST['Phone']."\n";
}
if isset($_POST['Fax']) {
$message = $message."Fax Number: ".$_POST['Fax']."\n";
}
if isset($_POST['Email']) {
$message = $message."E-Mail Address: ".$_POST['Email']."\n";
}
if isset($_POST['Manufacturer']) {
$message = $message."Manufacturer: ".$_POST['Manufacturer']."\n";
}
if isset($_POST['Model']) {
$message = $message."Model Number: ".$_POST['Model']."\n";
}
if isset($_POST['Serial']) {
$message = $message."Serial Number: ".$_POST['Serial']."\n";
}
if isset($_POST['Message']) {
$message = $message."Message: ".$_POST['Message']."\n";
}
if isset($_POST['ContactMethod']) {
$message = $message."Preferred Contact Method: ".
$_POST['ContactMethod']."\n";
}
mail( $to, $subject, $message, "From: $email" );
}
?>
Re: Undefine index error
am 05.09.2007 00:42:50 von shimmyshack
On Sep 4, 10:49 pm, JJM0926 wrote:
> I've got a contact form with a submit button where users have to enter
> their support information. Some fields are required some are not.
> When I test out the form if I leave everything blank I get these two
> undefined index error :
>
> Notice: Undefined index: CurrentCustomer in E:\WebSites\mysite\www
> \contactus.php on line 9
>
> Notice: Undefined index: ContactMethod in E:\WebSites\mysite\www
> \contactus.php on line 19
>
> If I fill out at least the required fields everything is fine.
>
> Here's what the code looks like:
>
>
> if (isset($_POST["Submit"])) // Trigger
> {
> // Email Request
> $to = "supp...@myisp.com";
> $subject = "Here Is My Contact Information";
> $email = $_POST['Email'];
> $message = "";
> if isset($_POST['CurrentCustomer']) {
> $message = $message."Current Customer: ".
> $_POST['CurrentCustomer']."\n";
> }
> if isset($_POST['Name']) {
> $message = $message."Name: ".$_POST['Name']."\n";
> }
> if isset($_POST['CoName']) {
> $message = $message."Company Name: ".$_POST['CoName']."\n";
> }
> if isset($_POST['Phone']) {
> $message = $message."Phone Number: ".$_POST['Phone']."\n";
> }
> if isset($_POST['Fax']) {
> $message = $message."Fax Number: ".$_POST['Fax']."\n";
> }
> if isset($_POST['Email']) {
> $message = $message."E-Mail Address: ".$_POST['Email']."\n";
> }
> if isset($_POST['Manufacturer']) {
> $message = $message."Manufacturer: ".$_POST['Manufacturer']."\n";
> }
> if isset($_POST['Model']) {
> $message = $message."Model Number: ".$_POST['Model']."\n";
> }
> if isset($_POST['Serial']) {
> $message = $message."Serial Number: ".$_POST['Serial']."\n";
> }
> if isset($_POST['Message']) {
> $message = $message."Message: ".$_POST['Message']."\n";
> }
> if isset($_POST['ContactMethod']) {
> $message = $message."Preferred Contact Method: ".
> $_POST['ContactMethod']."\n";
> }
> mail( $to, $subject, $message, "From: $email" );
> }
> ?>
i advise you to download a secure form that attempts to do some
checking before emailing.
as for the notices, use error_reporting(0) to turn off anything you
dont want, and google for programming standards, there are many
problems with the code as is, formatting, as well as $message =
$message .'blah' etc... I suggest a good read through the manual
before you expose your server and the world to spam and lots of it.
Re: Undefine index error
am 05.09.2007 02:35:45 von Jerry Stuckle
JJM0926 wrote:
> I've got a contact form with a submit button where users have to enter
> their support information. Some fields are required some are not.
> When I test out the form if I leave everything blank I get these two
> undefined index error :
>
> Notice: Undefined index: CurrentCustomer in E:\WebSites\mysite\www
> \contactus.php on line 9
>
> Notice: Undefined index: ContactMethod in E:\WebSites\mysite\www
> \contactus.php on line 19
>
Are you sure this is the code you're actually using?
The notices do not match up with the code you posted.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Undefine index error
am 05.09.2007 10:46:16 von Vladimir Ghetau
On Sep 4, 10:49 pm, JJM0926 wrote:
> I've got a contact form with a submit button where users have to enter
> their support information. Some fields are required some are not.
> When I test out the form if I leave everything blank I get these two
> undefined index error :
.....
After looking at your code.... all I can say is:
if (condition) {
do_task_one();
} elseif (condition) {
do_task_two();
} else {
read_documentation();
}
?>
Here's what I would do at this point:
- while the application is tested, it's cool to have
error_reporting(E_ALL); ?>, but when you're in production environment
(when people browse your site) error_reporting(0); ?> is
recommended to avoid revealing info about your code;
- instead of having
// ....
if isset($_POST['CurrentCustomer']) {
......
}
// ....
?>
I would go for:
//....
if (isset($_POST['CurrentCustomer'])) {
//....
}
?>
Also, make sure you change the email message building approach a
little bit, it allows people to inject "content-type" strings inside
your POSTS and easily deliver few hundred of emails to different
locations online.
Let me know how it goes!
Cheers!
Vladimir Ghetau
----------------------
http://www.Vladimirated.com
Re: Undefine index error
am 05.09.2007 11:53:13 von Csaba Gabor
On Sep 4, 11:49 pm, JJM0926 wrote:
> I've got a contact form with a submit button where users have to enter
> their support information. Some fields are required some are not.
> When I test out the form if I leave everything blank I get these two
> undefined index error :
>
> Notice: Undefined index: CurrentCustomer in E:\WebSites\mysite\www
> \contactus.php on line 9
>
> Notice: Undefined index: ContactMethod in E:\WebSites\mysite\www
> \contactus.php on line 19
>
> If I fill out at least the required fields everything is fine.
>
> Here's what the code looks like:
>
>
> if (isset($_POST["Submit"])) // Trigger
> { ... }
> if isset($_POST['Name']) {
> $message = $message."Name: ".$_POST['Name']."\n";
> }
> ...
> ?>
In place of isset, sometimes it's useful to use:
http://php.net/array_key_exists
Csaba Gabor from Vienna
Re: Undefine index error
am 05.09.2007 17:23:56 von jjm0926
On Sep 5, 3:46 am, Vladimir Ghetau wrote:
> On Sep 4, 10:49 pm, JJM0926 wrote:> I've got a contact form with a submit button where users have to enter
> > their support information. Some fields are required some are not.
> > When I test out the form if I leave everything blank I get these two
> > undefined index error :
>
> ....
>
> After looking at your code.... all I can say is:
>
>
> if (condition) {
>
> do_task_one();
>
> } elseif (condition) {
>
> do_task_two();
>
> } else {
>
> read_documentation();
>
> }
>
> ?>
>
> Here's what I would do at this point:
>
> - while the application is tested, it's cool to have
> error_reporting(E_ALL); ?>, but when you're in production environment
> (when people browse your site) error_reporting(0); ?> is
> recommended to avoid revealing info about your code;
>
> - instead of having
>
>
> // ....
> if isset($_POST['CurrentCustomer']) {
> .....
>
> }
>
> // ....
> ?>
>
> I would go for:
>
>
>
> //....
>
> if (isset($_POST['CurrentCustomer'])) {
>
> //....
>
> }
>
> ?>
>
> Also, make sure you change the email message building approach a
> little bit, it allows people to inject "content-type" strings inside
> your POSTS and easily deliver few hundred of emails to different
> locations online.
>
> Let me know how it goes!
>
> Cheers!
>
> Vladimir Ghetau
>
> ----------------------http://www.Vladimirated.com
Vladimir,
When I try what you suggested I get the following:
Parse error: parse error, unexpected $end in E:\WebSites\mywebsite\www
\contactus_revised.php on line 402