Current location: Hot Scripts Forums » Programming Languages » PHP » Undefined Index


Undefined Index

Reply
  #1 (permalink)  
Old 09-27-09, 05:02 PM
Webosphere Webosphere is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Undefined Index

I'm new to scripting and I'm trying to code an email contact form. Somehow, during testing when I press submit to test my form, all of my input variables return undefined. I have my php script contained in a separate file. Surprisingly enough, this happens with all of the form tutorials that I've tried recreating.

I'm wondering if this is either a scripting problem or a server problem. I just recently installed the server.

The tutorials that I've tried are the following. If you find no errors in their script, it might be a server issue.

<a href="http://php.about.com/od/phpapplications/ss/form_mail_3.htm">Tutorial 1</a>
<br />
<a href="http://www.phptoys.com/e107_plugins/content/content.php?content.44">Tutorial 2</a>

Test Server: WAMPServer 2.0 (PHP, APACHE, MySQL)
WebDev Prog: Dreamweaver CS4

Thanks in advance to anyone who might have an answer for me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-27-09, 06:05 PM
captcha captcha is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 24
Thanks: 0
Thanked 1 Time in 1 Post
Is the forms action="" really pointing to your php script?

Check if you get any errors:
PHP Code:

error_reportingE_ALL E_STRICT ); 

Check if the variables you`r trying to use are set:
PHP Code:

var_dump($_REQUEST); 

is php even working on your server?
does <?php phpinfo(); ?> for ex. show something?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-27-09, 07:30 PM
Webosphere Webosphere is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
captcha:

1.
Quote:
<?php phpinfo(); ?>
returns an entire page of data.

2.
Quote:
error_reporting( E_ALL | E_STRICT );
doesn't seem to do anything. The error message still comes up.

3.
Quote:
var_dump($_REQUEST);
has output the following: array(0) { }

4. Yes the action= is pointing to my php document.

5. I've created a new PHP document and pointed to it in order to test certain bits of code. The problem might be starting in the SUPER GLOBAL ARRAYS since _POST, _GET, and _REQUEST return the error:

Quote:
Notice: Undefined index: (variable name) in C:\wamp\www\contact.php on line #

Last edited by Webosphere; 09-27-09 at 07:41 PM. Reason: Added #4 and #5
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-27-09, 08:17 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
1. What version of PHP are you using?

2. The error reporting settings won't cause any action until an error, when they will ensure the error message is displayed, rather than just being logged.

3. array(0) {} on a var_dump means no data was received, either through $_POST or $_GET. Please post your HTML, or the previous page of PHP.

4. Good

5. The undefined index is because no data is being received.

Please post the HTML and PHP.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-27-09, 08:53 PM
Webosphere Webosphere is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
I'm using PHP version 5.3.0

HTML:
Quote:
<form action="contact.php" method="post">
<h1>CONTACT</h1>
<br />
Send to:
<br />
<select name="sendto">
<option value="name@someaddress.com">Webmaster</option>
<option value="name@someaddress.com">General</option>
</select>
<br />
<br />
Name:
<br />
<input name="name" type="text" />
<br />
<br />
Email:
<br />
<input name="email" type="text" id="email" size="30"/>
<br />
<br />
Message:
<br />
<textarea name="comments" cols="50" rows="10" id="comments" ></textarea>
<br />
<br />
Subscribe to recieve FREE newsletter?
<br />
<br />
<input type="radio" name="list" value="No"> No Thanks
<br />
<input type="radio" name="list" value="Yes" checked> Yes, keep me informed.
<br />
<br />
<input type="submit" name="send" value="Send!" />
</form>
*Note: The email addresses have been removed so I won't get spammed.

PHP Code:
Quote:
<?php
$to = $_REQUEST['sendto']
$from = $_REQUEST['email']
$name = $_REQUEST['name']
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields["name"] = "First Name";
$fields["email"] = "Email";
$fields["list"] = "Mailing List";
$fields["comments"] = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b, $_REQUEST[$a]); }

$headers2 = "From: noreply@someaddress.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.someaddress.com";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster@someaddress.com"; }
}
}
?>
Is there something I'm missing about where to save files. I have my website root folders in My Documents where dreamweaver initially wanted me to save files. However, after installing WAMPServer, should I have moved all of my website root directories to the www folder or is that folder just for testing the php documents alone? Whenever I go to view my PHP files, Dreamweaver wants to "put" the files on my test server. Is this an acceptable way to work with PHP? How should I be doing this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-27-09, 09:22 PM
Webosphere Webosphere is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
I told the PHP document to:

Quote:
print "To: {$to}";
And it printed the data from the form.

Should I be using POST instead of REQUEST?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-28-09, 08:00 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
$_POST is more secure.

If you leave the sendto address in the form, it will be picked up by spammers. Better to hard-code it in the PHP that sends the email.

You should also do some research into ways to make your form more secure. I think your code would allow people to spam from it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-29-09, 02:24 AM
Webosphere Webosphere is offline
Newbie Coder
 
Join Date: Sep 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Are you suggesting that I rename "sendto" or just that I change the value of name@address.com to something like "email1"?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
apache, error, scripting, server, variable


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR - Notice: Undefined index: - ERROR tommyc325 PHP 5 11-11-08 07:40 PM
[SOLVED] No page no error? Hamed PHP 11 07-19-08 01:39 AM
No error message... stormshadow PHP 3 12-11-06 07:31 PM
Problems getting PHP-Nuke setup correctly TravisT PHP 2 12-17-05 08:54 PM
Undefined index: a - help andrewvideo PHP 5 05-17-05 04:33 PM


All times are GMT -5. The time now is 12:07 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.