Re: PHP error on form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I made the suggestions mentioned by Mike and don't get any error, but
the form doesn't work properly. Check it out at
http://www.inspired-evolution.com/Contact_Form_test.php

the PHP form CODE I now have is:
<?
$form_block = "
<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
<p><strong>Your Name:</strong></p>
<INPUT type=\"text\" NAME=\"senders_name\" SIZE=30></p>
<p><strong>Your E-mail Address:</strong><p>
<INPUT type=\"text\" NAME=\"senders_email\" SIZE=30></p>
<p><strong>Message:</strong></p>
<TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></p>
<INPUT type=\"hidden\" name=\"op\" value=\"ds\">
<p><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send this Form\"></p>
</FORM>";

if ($_POST['op'] !="ds") {
// they need to see the form
echo "$form_block";
} else if ($_POST['op'] =="ds") {
//check value of $_POST['sender name']
if ($_POST['sender_name'] =="") {
			$name_err = "<font color=red>Please enter your name!</font><br />";
			$send = "no";
}
//check value of $_POST['sender_email']
if ($POST['sender_email'] =="") {
		$email_err ="<font color=red>Please enter your email address!</font><br />";
		$send= "no";
}
//check value of $_POST['message']
if ($POST['message'] =="") {
		$message_err = "<font color=red>Please enter a message!</font><br />";
		$send ="no";
}
if ($send !="no") {
//it's o.k to send, so build the mail
		$msg ="E-MAIL SENT FROM WWW SITE\n";
		$msg .="Senders Name:		$POST{['senders_name']}\n";
		$msg .="Senders E-MAIL:			$POST{['senders_email']}\n";
		$msg .="Senders Name:		{$POST['message']}\n\n";
		$to ="webguync@xxxxxxxxx";
		$subject = "There has been a disturbance in the Force";
		$mailheaders .="Reply-To: {$_POST['sender_email']}\n";
//send the mail
		mail ($to, $subject, $msg, $mailheaders);
		//display confirmation to user
		echo "<p>mail has been sent!</p>";
} else if ($send =="no") {
		//print error messages
		echo "$name_err";
		echo "$email_err";
		echo "$message_err";
		echo "$form_block";
	}
}
?>




On 7/28/05, Mike Johnson <mike@xxxxxxxxxxxxxxxxx> wrote:
> From: Bruce Gilbert [mailto:webguync@xxxxxxxxx] 
> 
> > Hello,
> > 
> > I am trying to get a form to work integrating html with PHP.
> > 
> > the code I have is:
> > 
> > <?
> > $form_block = "
> > <FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
> > <p><strong>Your Name:</strong>< /br>
> > <INPUT type=\"text\" NAME=\"senders_name\" SIZE=30></p>
> > <p><strong><p><Your E-mail Address:</strong>< /br>
> > <INPUT type=\"text\" NAME=\"senders_email\" SIZE=30></p>
> > <p><strong>Message:</strong>< /br>
> > <TEXTAREA NAME=\"message\" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></p>
> > <INPUT type=\"hidden\" name=\"op\" value=\"ds\">
> > <p><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send this 
> > Form\"></p>
> > </FORM>";
> > 
> > if ($_POST['op'] !="ds") {
> > // they need to see the form
> > echo "$form_block";
> > } else if ($_POST['op'] =="ds") {
> > //check value of $_POST['sender name']
> > if ($_POST['sender_name'] =="") {
> > 			$name_err = "<font color=red>Please 
> > enter your name!</font>< /br>";
> > 			$send ="no";
> > }
> > //check value of $_POST['sender_email']
> > if ($POST['sender_email'] =="") {
> > 		$email_err ="<font color=red>Please enter your 
> > email address!</font>< /br>";
> > 		$send= "no";
> > }
> > //check value of $_POST['message']
> > if ($POST['message'] =="") {
> > 		$message_err = "<font color=red>Please enter a 
> > message!</font>< /br>";
> > 		$send ="no";
> > }
> > if ($send !="no") {
> > //it's o.k to send, so build the mail
> > 		$msg ="E-MAIL SENT FROM WWW SITE\n";
> > 		$msg .="Senders Name:		
> > $POST['senders_name']\n";
> > 		$msg .="Senders E-MAIL:			
> > $POST['senders_email']\n";
> > 		$msg .="Senders Name:		$POST['message']\n\n";
> > 		$to ="webguync@xxxxxxxxx";
> > 		$subject = "There has been a disturbance in the Force";
> > 		$mailheaders .="Reply-To: $_POST['sender_email']\n";
> > //send the mail
> > 		mail ($to, $subject, $msg, $mailheaders);
> > 		//display confirmation to user
> > 		echo "<p>mail has been sent!</p>";
> > } else if ($send =="no") {
> > 		//print error messages
> > 		echo "$name_err";
> > 		echo "$email_err";
> > 		echo "$message_err";
> > 		echo "$form_block";
> > 	}
> > }
> > ?>
> > 
> > and the error I get is:
> > 
> > Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
> > expecting T_STRING or T_VARIABLE or T_NUM_STRING in
> > /hsphere/local/home/bruceg/inspired-evolution.com/Contact_Form
> > _test.php
> > on line 58
> > 
> > the above code is just the php form part of the page not the entire
> > code, so it would be impossible to determine line 58, but I was hoping
> > someone would be able to spot the problem or at least explain the
> > error to a relative newbie.
> > 
> > thanks
> 
> I don't think your error message is indicative of this, but PHP /will/
> choke on your lines that include array key references in them, such as:
> 
> $mailheaders .="Reply-To: $_POST['sender_email']\n";
> 
> In those cases, you need to either leave the quotes for the variable or
> enclose the var in curly braces:
> 
> $mailheaders .="Reply-To: " . $_POST['sender_email'] . "\n";
> $mailheaders .="Reply-To: {$_POST['sender_email']}\n";
> 
> I generally prefer the latter, but it's entirely up to the user.
> 
> Try fixing those and see if it still errors.
> 
> -- 
> Mike Johnson             Smarter Living, Inc.
> Web Developer            www.smartertravel.com
> mike@xxxxxxxxxxxxxxxxx   (617) 886-5539
> 
> 


-- 
::Bruce::

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux