By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,724 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,724 IT Pros & Developers. It's quick & easy.

need help

P: n/a
Can someone give me a pointer, please.

I am getting the following errors:
Notice: Undefined index: sender_name in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 12

Notice: Undefined index: sender_email in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 14

Notice: Undefined index: message in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 16

Notice: Undefined index: op in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 24

Here is my script:

<html>
<head>
<title>All-In-One Feedback Form</title>
</head>

<body>

<?
$form_block = "
<form method=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">
<p><strong>Your Name:<br>
<input type=\"text\" name=\"sender_name\" value=\"$_POST[sender_name]\"
size=30></p>
<p><strong>Your Email Address:<br>
<input type=\"text\" name=\"sender_email\" value=\"$_POST[sender_email]\"
size=30></p>
<p><strong>Message:</strong><br>
<textarea name=\"message\" cols=50 rows=5 wrap=virtual>$_POST[message]
</textarea></p>
<input name=\"op\" type=\"hidden\" value=\"ds\">
<p><input type=\"submit\" name=\"submit\" value\"Send This Form\"></p>
</form>";

$send = "yes";

if ($_POST["op"] !="ds") {

//they need to see the form
echo "$form_block";
}
else if ($_POST["op"] == "ds") {
if ($_POST["sender_name"] == ""){
$name_err = "<font color=red>Please enter your name!</font><br>";
$send = "no";}
else if ($_POST["sender_name"] != "")
{$name_err = "";}
if ($_POST["sender_email"] == "")
{$email_err = "<font color=red>Please enter your email
address!</font><br>";
$send = "no";}
else if ($_POST["sender_email"] != "")
{$email_err = "";}
if ($_POST["message"] == "")
{$message_err = "<font color=red>Please enter a message!</font><br>";
$send = "no";}
else if ($_POST["message"] != "")
{$message_err = "";}

if ($send != "no")
{
// it's ok to send!!
$to = "me@me.net";
$subject = "All-in-one Web Site Feedback";
$mailheaders = "From: My Web Site <> \n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n\n";

$msg = "E-MAIL SEND FROM WWW SITE\n";
$msg .= "Sender's Name: $_POST[sender_name]\n";
$msg .= "Sender's E-mail: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";

mail($to, $subject, $msg, $mailheaders);

echo "<p>Mail has been sent!</p>";
}
else if ($send == "no")
{
echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
}
}
?>
</body>
</html>
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Jerry Polyak" <jerrypolyak@NOSPAM_yahoo.com> wrote in message
news:FO********************@adelphia.com...
Can someone give me a pointer, please.

I am getting the following errors:
Notice: Undefined index: sender_name in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 12

Notice: Undefined index: sender_email in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 14

Notice: Undefined index: message in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 16

Notice: Undefined index: op in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 24

Here is my script:

<snip>

It's fine, your errors are really warnings as a result of the first run of
the script not having anything in the $_POST variable to use as value=
attributes; presumably you've put them there because you want to repost the
same data if there's an error.

You could code round it, but it's easier to just put
error_reporting(E_ERROR);
at the top once you're satisfied that it works to your satisfaction. Or,
like me, even change the default in php.ini so that E_ERROR is usual and put
error_reporting(E_ALL); at the top of scripts that you're debugging.

HTH
Garp
Jul 17 '05 #2

P: n/a

"Garp" <ga***@no7.blueyonder.co.uk> wrote in message
news:TE*********************@news-text.cableinet.net...

"Jerry Polyak" <jerrypolyak@NOSPAM_yahoo.com> wrote in message
news:FO********************@adelphia.com...
Can someone give me a pointer, please.

I am getting the following errors:
Notice: Undefined index: sender_name in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 12

Notice: Undefined index: sender_email in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 14

Notice: Undefined index: message in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 16

Notice: Undefined index: op in c:\program files\apache
group\apache\htdocs\allinone_form.php on line 24

Here is my script:
<snip>

It's fine, your errors are really warnings as a result of the first run of
the script not having anything in the $_POST variable to use as value=
attributes; presumably you've put them there because you want to repost

the same data if there's an error.

You could code round it, but it's easier to just put
error_reporting(E_ERROR);
at the top once you're satisfied that it works to your satisfaction. Or,
like me, even change the default in php.ini so that E_ERROR is usual and put error_reporting(E_ALL); at the top of scripts that you're debugging.

HTH
Garp


Excellent, thank you.

I figured that is what the problem is (nothing to use for value), but had no
idea of the workaround. Kind of new to PHP.

Thanks again.
Jul 17 '05 #3

P: n/a
"Garp" <ga***@no7.blueyonder.co.uk> schrieb im Newsbeitrag
news:TE*********************@news-text.cableinet.net...


It's fine, your errors are really warnings as a result of the first run of
the script not having anything in the $_POST variable to use as value=
attributes; presumably you've put them there because you want to repost the same data if there's an error.

You could code round it, but it's easier to just put
error_reporting(E_ERROR);
at the top once you're satisfied that it works to your satisfaction. Or,
like me, even change the default in php.ini so that E_ERROR is usual and put error_reporting(E_ALL); at the top of scripts that you're debugging.


Killing notices IMO is not debugging, but rather bugging! You can disable
the notice reporting _after_ debugging on going online, to prevent notices
from being displayed to the public, but they are essential for debugging.

For a quick solution, just fill the variables before you display the form:

if(isset($_POST['sender_name'])) $sender_name=$_POST['sender_name'];
else $sender_name="";

.... and so on. After that you just use $sender_name. Also note the 'quotes'
inside the ['brackets'].

A better solution would be to display the form at the end of the code flow.
So you can handle all your variable checking, then display a thank you
message if all is ok or display the form again with the messages and the
entries if it has to be resubmitted.

HTH
Markus
Jul 17 '05 #4

P: n/a

"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:40**********************@news.easynet.ch...
"Garp" <ga***@no7.blueyonder.co.uk> schrieb im Newsbeitrag
news:TE*********************@news-text.cableinet.net...


It's fine, your errors are really warnings as a result of the first run of the script not having anything in the $_POST variable to use as value=
attributes; presumably you've put them there because you want to repost the
same data if there's an error.

You could code round it, but it's easier to just put
error_reporting(E_ERROR);
at the top once you're satisfied that it works to your satisfaction. Or,
like me, even change the default in php.ini so that E_ERROR is usual and

put
error_reporting(E_ALL); at the top of scripts that you're debugging.


Killing notices IMO is not debugging, but rather bugging! You can disable
the notice reporting _after_ debugging on going online, to prevent notices
from being displayed to the public, but they are essential for debugging.


Isn't that what I said? I use E_ALL while debugging, then remove it and keep
warnings hidden while keeping actual errors visible? I was in a hurry, maybe
I phrased it badly.

For a quick solution, just fill the variables before you display the form:

if(isset($_POST['sender_name'])) $sender_name=$_POST['sender_name'];
else $sender_name="";

... and so on. After that you just use $sender_name. Also note the 'quotes' inside the ['brackets'].

A better solution would be to display the form at the end of the code flow. So you can handle all your variable checking, then display a thank you
message if all is ok or display the form again with the messages and the
entries if it has to be resubmitted.


So like I said, you could code round it...

Garp
Jul 17 '05 #5

P: n/a

"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:40**********************@news.easynet.ch...
"Garp" <ga***@no7.blueyonder.co.uk> schrieb im Newsbeitrag
news:TE*********************@news-text.cableinet.net...


It's fine, your errors are really warnings as a result of the first run of the script not having anything in the $_POST variable to use as value=
attributes; presumably you've put them there because you want to repost the
same data if there's an error.

You could code round it, but it's easier to just put
error_reporting(E_ERROR);
at the top once you're satisfied that it works to your satisfaction. Or,
like me, even change the default in php.ini so that E_ERROR is usual and

put
error_reporting(E_ALL); at the top of scripts that you're debugging.


Killing notices IMO is not debugging, but rather bugging! You can disable
the notice reporting _after_ debugging on going online, to prevent notices
from being displayed to the public, but they are essential for debugging.

For a quick solution, just fill the variables before you display the form:

if(isset($_POST['sender_name'])) $sender_name=$_POST['sender_name'];
else $sender_name="";

... and so on. After that you just use $sender_name. Also note the

'quotes' inside the ['brackets'].

A better solution would be to display the form at the end of the code flow. So you can handle all your variable checking, then display a thank you
message if all is ok or display the form again with the messages and the
entries if it has to be resubmitted.

HTH
Markus


Makes sense. As I said, I'm new to this. The form does what it has to, so
turning off debugging worked fine.

But I also see how filling the variables would work. Thanks for the tip. I
am sure I will use it in the future. For now this school assignment has
taken enough of my time.

Thanks to everyone for the help.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.