473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Undefine index error

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:

<?php
if (isset($_POST["Submit"])) // Trigger
{
// Email Request
$to = "su*****@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" );
}
?>

Sep 4 '07 #1
3 2040
On Sep 4, 10:49 pm, JJM0926 <jjm0...@gmail.comwrote:
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:

<?php
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.

Sep 4 '07 #2
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.
js*******@attglobal.net
==================
Sep 5 '07 #3
On Sep 4, 11:49 pm, JJM0926 <jjm0...@gmail.comwrote:
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:

<?php
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

Sep 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sam | last post by:
HI, I installed php4 for apached and restart apache afterward. but my little php script generated error followint error: PHP Notice: Undefined index: myname in...
12
by: Tuhin Kumar | last post by:
Hi, Oracle give the error ORA-01418 when I try to do the following; Create unique index t1_pk on TABLE1(EntryId DESC) ; If the I try to add primary key Contraint using the above index t1_pk...
1
by: Rafal 'Raf256' Maj | last post by:
Hi, is there a commend to undefine all macros #define inside a file? in example: #define FOR(x) for (..............) #define MyMacro1(x,y) ........... // ... code ...
1
by: Clark Choi | last post by:
I ran the sample application called Petstore from msdn. Everything went fine until I tested Update button on the web form to update the database through Datagrid. I have been searching the web to...
14
by: Rich | last post by:
I am converting my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 (.NET v2.0.50727). The entire solution uses serveral technologies - Windows Server 2003 (AD, SQL Server 2000, IIS,...
7
by: Alden Pierre | last post by:
Hello, I'm trying to create my own user define container, but I'm having a little hard time figuring out why is my class considered undefined by my compiler. Here is the following code. //...
5
by: Rocky86 | last post by:
hi people basically I am having a problem with the followinng code: $names=sizeof($temp); $report="total=$names&"; foreach($temp as $list) $report.="name".$names--."=".$list."&"; echo...
6
by: Pietro Cerutti | last post by:
Hi Group, is there a mean to undefine a function, in a similar way as you can undefine macros? For example, let's say that I need a few declarations from stdio.h but want to define my own...
4
rahulephp
by: rahulephp | last post by:
i think i am missing something in the below script: It shows error an do not upload files to destination: Let me know how to solve this: <?php if (isset($_POST)) { $uploadArray=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.