PHP Notice: Undefined index

08-18-08, 03:28 PM
|
|
Newbie Coder
|
|
Join Date: Aug 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
PHP Notice: Undefined index
Hi all,
I'm new to PHP. I wrote a basis PHP script to send data from a web form into an email. The script is working fine and able to send the data into the specific email address. However, after you click on the submit button, the PHP Notice: Undefined index log display. Anyone has any idea how to get this issue resolved.
|

08-18-08, 03:37 PM
|
|
Newbie Coder
|
|
Join Date: Aug 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
PHP Notice: Undefined index
Attached is my PHP Script.
Hi all,
I'm new to PHP. I wrote a basis PHP script to send data from a web form into an email. The script is working fine and able to send the data into the specific email address. However, after you click on the submit button, the PHP Notice: Undefined index log display. Anyone has any idea how to get this issue resolved.[/QUOTE]
|

08-18-08, 04:58 PM
|
|
Newbie Coder
|
|
Join Date: Jul 2008
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Could you paste your script here?
|

08-19-08, 12:16 AM
|
|
Junior Code Guru
|
|
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cant see any attachments.
Anyway, "undefined index" means just that, your trying to access a array element named "log display" which doesnt exist. You can make the error disappear by defining a default value for the variable
|

08-27-08, 01:51 PM
|
|
Newbie Coder
|
|
Join Date: Aug 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi all,
Sorry for the delay in responding. Anyways, thanks for all of your tried to help. I did find the solution to my problem. Below is my PHP script with the solution. Error_reporting(E_ALL^E_NOTICE); is the answer to the undefined index.
Last edited by mab; 08-27-08 at 01:58 PM.
Reason: Code in code tags please.
|

08-27-08, 02:04 PM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Disabling notice messages does not actually fix anything. The error is still occurring, causing php to take 10 to 20 times longer to execute the line of code where the error is.
If you post the actual error message, someone can help you find the cause.
I am going to assume this is purely a learning exercise as the posted code is not validating the input from the form and would allow a hacker or a spam bot script to send anything to anyone.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
|

08-28-08, 08:49 AM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
Quote:
Originally Posted by pher
I did find the solution to my problem. Below is my PHP script with the solution. Error_reporting(E_ALL^E_NOTICE); is the answer to the undefined index.
|
Actually all E_ALL^E_NOTICE does suppress the printing of the error message. As mab mentioned it doesn't fix anything. It's like putting a band-aid on a cut- the cut is still there, you just can't see it. You're better off fixing the actual problem by simply assigning a default value to the variable.
|

08-28-08, 01:52 PM
|
|
Newbie Coder
|
|
Join Date: Aug 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If I took the Error_reporting(E_ALL^E_NOTICE) out of the script, then following message display. However, I did get the data fill on the form email to me as I expected. The following message display only when at least one field was not filled in. Otherwise, the script is working.
PHP Notice: Undefined index: FirstName in D:\ATCWeb\scripts\librarianform.php on line 7 PHP Notice: Undefined index: LastName in D:\ATCWeb\scripts\librarianform.php on line 8 PHP Notice: Undefined index: Email in D:\ATCWeb\scripts\librarianform.php on line 9 PHP Notice: Undefined index: WorkPhone in D:\ATCWeb\scripts\librarianform.php on line 10 PHP Notice: Undefined index: HomePhone in D:\ATCWeb\scripts\librarianform.php on line 11 PHP Notice: Undefined index: Question in D:\ATCWeb\scripts\librarianform.php on line 12 PHP Notice: Undefined index: SourcesChecked in D:\ATCWeb\scripts\librarianform.php on line 13 PHP Notice: Undefined index: Contact in D:\ATCWeb\scripts\librarianform.php on line 14
|

08-28-08, 08:36 PM
|
|
Newbie Coder
|
|
Join Date: Aug 2008
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
put this 'error_reporting(0)" into your files
|

08-29-08, 02:15 AM
|
 |
Community Liaison
|
|
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
|
|
NO: putting that on top of your code doesn't solve the problems, it hides the problems.
The problem is pretty straightforward: you're trying to access elements of the $_REQUEST array, but they don't exist yet. Here's an example:
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|