Jump to content

Notice: Undefined index......on line 166


stealthmode666

Recommended Posts

I threw myself in headfirst into php5. I have created a massive form page which uses a .php script to extract the data from the form page and email it to my chosen email address. I have just used an ARRAY as in "$fields = array();"

I still have to add some validation to the form page but unless I fill in every part of the form I get a page of this error displaying.

 

"Notice:Undefined index: homeowner in E:\r\...\user\htdocs\....\form.php"

 

I'm new to .php 5 so it may take me a little while to get round to understanding but I will get there with some help

Link to comment
https://forums.phpfreaks.com/topic/134672-notice-undefined-indexon-line-166/
Share on other sites

It is a notice, not a warning or error (i.e. it's not fatal)

 

This happens, when you have code like this

$something = $_POST['something']

and $_POST['something'] has not been filled in the form.

 

If you want to get rid of it, you have to check if value from form is set (isset) before trying to use it.

 

 

This is all I've used as my script. I pieced this together in notepad as best I could. I do not have (isset()) anywhere.

How would I insert that into what I have below?

 

 

<?php

$to = $_REQUEST['sendto'] ;

$from = $_REQUEST['Email'] ;

$name = $_REQUEST['Member_Name'] ;

$headers = "From: $from";

$subject = "";

 

$fields = array();

 

$body = "my message to the email:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

$headers2 = "From: [email protected]";

$subject2 = "Thank-you for...";

$autoreply = "Somebody ......";

 

if($from == '') {print "...";}

else {

if($name == '') {print "...";}

else {

$send = mail($to, $subject, $body, $headers);

$send2 = mail($from, $subject2, $autoreply, $headers2);

if($send)

{header( "Location: http://www...com/../thankyou.html" );}

else

{print "We encountered an error sending your mail, please notify @.com"; }

}

}

?>

 

 

 

Enclose your code in [ code] [ /code] tags for better visibility please

 

Your code seems to have no sense:


$fields = array();

$body = "my message to the email:\n\n"; 
foreach($fields as $a => $b) { 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); 
} 

 

$fields is an empty array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.