php/html form error-not sure why

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

php/html form error-not sure why

Post by bruceg »

Hello All.

I am fairly new at PHP and struggling along, so please be patient with me.

the form I am working on is based upon a book tutorial, that I have entered manually and don't have an editor that color codes PHP errors, so that is part of my problem! Anyway, I am receiving an error msg that states 'Parse error: parse error, unexpected T_STRING in /hsphere/local/home/bruceg/inspired-evolution.com/Contact_Form.php on line 39'

I assume this means I may be missing a ; or something similar, but I have double checked and don't see anything.

here is the ENTIRE code on the page:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>Inspired Evolution :: Contact</title>
<?php require('includes/meta_tags.inc'); ?>
<link rel="stylesheet" href="Gilbert.css" type="text/css" media="screen, handheld" />
</head>
<body>
<!-- begin outer wrapper div --> 

<div id="wrapper_outer">
<a class="skiplink" href="#startcontent">Skip over navigation</a>
<!-- begin header div --> 
<div id="header"><?php require('images/Rotating_Banner/rotating_banner.php'); ?></div>
<!-- top nav list --> 
<div id="navcontainer">
<ul id="navlist">
<li ><a href="About_Me.php" title="you know you want to learn more about me">About Me</a></li>
<li><a href="Skillset.php" title="I've got skillz">Skill set</a></li>
<li><a href="Hireme.php" title="I can do wonders for your web presence">Hire Me</a></li>
<li><a href="Portfolio.php" title="web sites, graphics, newsletters">Portfolio</a></li>
<li><a href="Contact.php"  title="how to get in touch with me">Contact</a></li>
<li><a href="Resume.php"  title="my beautiful resume">R&eacute;sum&eacute;</a></li>
<li><a href="Blog.php"  title="My musings on everyday life" >Blog</a></li>
<li><a href="RSS.php"  title="Syndication that is really simple" >RSS</a></li>

</ul>
</div>
<!-- inner content wrapper div --> 
<div id="wrapper_inner">
<!-- breadcrumbs div --> 
<div id="breadcrumbs"><a href="index.php" title="home link" accesskey="1">Home</a>  > >  Contact</div>
<!-- text div --> 
<div id="main_content">
<a name="startcontent" id="startcontent"></a>
<h1 title="Contact">Contact</h1>
<?php
	$form_block = "
<form method=\"POST\" action=\" $PHP_SELF\" class=\"info_request\">
<fieldset>
<legend title="additional information request">Additional Information Request</legend>
<table id="info_request">
<tr>
<td>
<label for="firstname"><span class="red">*</span> First Name: </label></td>
<td>
<input id="firstname" name="firstname" type="text" value="$_POST['firstname']  />
</td>
</tr>
<tr>
<td>
<label for="lastname"><span class="red">*</span> Last Name:</label></td>
<td>
<input id="lastname" name="lastname" type="text" value="$_POST['lastname']  />
</td>
</tr>
<tr>
<td>
<label for="company"><span class="red">*</span> Company: </label></td>
<td>
<input id="company" name="company" type="text" value="$_POST['company']  /></td>
</tr>
<tr>
<td>
<label for="phone"><span class="red">*</span> Phone: </label></td>
<td>
<input  id="phone" name="phone" type="text" value="$_POST['phone']  /></td>
</tr>
<tr>
<td>
<label for="email"><span class="red">*</span> e-mail: </label></td>
<td>
<input  id="email" name="email" type="text" value="$_POST['email']  /></td>
</tr>
<tr>
<td>
<label for="email2"><span class="red">*</span> re-enter e-mail: </label></td>
<td>
<input  id="email2" name="email2" type="text" value="$_POST['email2']  />

</td>
</tr>
<tr>
<td>
<label for="URL"> URL:</label></td>
<td>
<input id="URL" type="text" name="URL" /> </td>
</tr>
<tr>
<td>
<label for="Contact_Preference"> Best way to reach:</label></td>
<td>
<input id="Contact_Preference" type="text" name="Contact_Preference" value="$_POST['Contact_Preference']  /></td>
</tr>
<tr>
<td>
<label for="Contact_Time"> Best time to contact:</label></td>
<td>
<input id="Contact_Time" type="text" name="Contact_Time" value="$_POST['Contact_Time']  />
</td>
</tr>
<tr>
<td valign="top">
<label for="message" id="message"> message:</label></td>
<td>
<textarea name="Textarea" rows="25" cols="50">Send me a detailed message specifying what you wish to accomplish with your web site.</textarea>
<input class="submit" src="/images/submit.gif" alt="Submit" type="image" name="submit"  /> 
</td>
</tr>
</table>
</fieldset>
</form>" ;

if ($_POST[op] !="ds")	 {
	// they need to see the form
	echo "$form_block";
	} else if ($_POST[op]  == "ds")  {
		// check value of $_POST['firstname']
		if ($_POST['firstname'] == " ")  {
			$name_err = '<span class="red">Please enter your first name!</span>< /br>';
			$send = "no" ;
	}
// check value of $POST['email']
if ($_POST ['email'] == " ")  {
	$email_err ='<span class="red">Please enter your email address!</span><br />';
	$send="no";
}
if ($send != "no") {
		//it's ok to send, so build the mail
		$msg = "E-mail sent from www site\n";
		$msg .="Sender's first name:		$_POST [firstname]\n";
		$msg .="Sender's last name:		$_POST [lastname]\n";
		$msg .="Company name:		$_POST [company]\n";
		$msg .="Senders Phone number:		$_POST [phone]\n";
		$msg .="Senders email address:		$_POST [email]\n";
		$msg .="Senders email address (re-typed):		$_POST [email2]\n";
		$msg .="URL :		$_POST[URL]\n";
		$msg .="Contact_Preference" $_POST[ Contact_Preference]\n";
				$msg .="Contact_Time" $_POST[ Contact_Time]\n";
		$msg .="Message:		$_POST [message]\n\n";
		$to ="webguync@gmail.com";
		$subject ="There has been a disturbance in the force";
		$mailheaders .="From: My Web Site
		<http://www.inspired-evolution.com>\n";
		$mailheaders .="Reply-To: $_POST [email]\n";
		//send the mail
		mail ($to, $subject, $msg, $mailheaders);
		//display information to user
  echo "<p>Hola, <strong>$firstname</strong>!.<br /><br />
We have received your request for additional information, and will respond shortly.<br />
Thanks for visiting inspired-evolution.com and have a wonderful day!<br /><br />
Regards,<br /><br />
<strong>Inspired Evolution</strong></p>";

} else if ($send =="no") {
		//print error messages
		echo "$name_err";
		echo $email_err";
		echo "$message_err";
		echo "$form_block";
		}

}
?.
	
<p><span class="red">*</span> indicates a required field.</p>
<p></p>
<p></p>
<?php require('includes/bottom_links.inc'); ?></div>

<!-- begin footer --> 
<div id="footer">
<p class="footertag">Inspired-Evolution - Web Site: Design, Development, Marketing for Raleigh/Durham, Chapel Hill, Cary North Carolina.</p>

<?php require('includes/footer.inc'); ?>
<span class="date"><?
$last_modified = filemtime("index.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?></span>
</div>

</div>
</div>

</body>

</html>
there may be some other obvious errors. Feel free to point those out as well, but for now, I am looking to solve the original error, that is not allowing my form to display.

a couple of ending questions.....

is there a way to turn off the errors so the form will display anyway?
For the textarea part of the form I am wanting to have the content not disappear if there is a validation error elsewhere .The other fields I have added value="$_POST['whatever'] do I do the same with textarea?

eg:

&lt;textarea name="Textarea" rows="25" cols="50"&gt;Send me a detailed message specifying what you wish to accomplish with your web site.value="$_POST['Textarea']&lt;/textarea&gt;

or is there another way??

sorry for the long post, but any assistance is greatly appreciative as I get over this "hump"!
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you are not escaping your quotes on line 39s $form_block, see what it looks like with the color coding here?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

I would suggest converting the form from line 39 to 113 to a heredoc. ie

Code: Select all

$form_block=<<<END_FORM
<form method="post" action="$PHP_SELF" class="info_request">
...
</form>
END_FORM; //ABSOLUTELY NO SPACES BEFORE END_FORM on this line!!!!
You an still stick variables into a heredoc, but you don't need to escape double quotes, so its ideal for long sections of HTML.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

shiznatix wrote:you are not escaping your quotes on line 39s $form_block, see what it looks like with the color coding here?

I don't see anything. Did you post the correction?

also, anyone have answers for my questions at the end?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

echo "this will generate "a" parse error error because the quotes wern't escaped";

Code: Select all

echo "this will not generate \"a\" parse error error because the quotes were escaped";
or if you don't like going through and fixing all your quotes you could convert your encapsulating double quotes to single quotes

Code: Select all

echo 'i dont need to escpape "double" quotes here';

Code: Select all

echo 'but I need escape single \'quotes\' though still';

Code: Select all

echo 'I also need to escape variables in single quotes '.$orelse .' the variables will be treated as a literal string';
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

well, I got past the first error, but I am getting another error that perhaps can be pointed out or explained.

the error "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.php on line 43"

the code I now have:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>Inspired Evolution :: Contact</title>
<?php require('includes/meta_tags.inc'); ?>
<link rel="stylesheet" href="Gilbert.css" type="text/css" media="screen, handheld" />
</head>
<body>
<!-- begin outer wrapper div --> 
<div id="wrapper_outer">
<a class="skiplink" href="#startcontent">Skip over navigation</a>
<!-- begin header div --> 
<div id="header"><?php require('images/Rotating_Banner/rotating_banner.php'); ?></div>
<!-- top nav list --> 
<div id="navcontainer">
<ul id="navlist">
<li ><a href="About_Me.php" title="you know you want to learn more about me">About Me</a></li>
<li><a href="Skillset.php" title="I've got skillz">Skill set</a></li>
<li><a href="Hireme.php" title="I can do wonders for your web presence">Hire Me</a></li>
<li><a href="Portfolio.php" title="web sites, graphics, newsletters">Portfolio</a></li>
<li><a href="Contact.php"  title="how to get in touch with me">Contact</a></li>
<li><a href="Resume.php"  title="my beautiful resume">R&eacute;sum&eacute;</a></li>
<li><a href="Blog.php"  title="My musings on everyday life" >Blog</a></li>
<li><a href="RSS.php"  title="Syndication that is really simple" >RSS</a></li>
</ul>
</div>
<!-- inner content wrapper div --> 
<div id="wrapper_inner">
<!-- breadcrumbs div --> 
<div id="breadcrumbs"><a href="index.php" title="home link" accesskey="1">Home</a>  > >  Contact</div>
<!-- text div --> 
<div id="main_content">
<a name="startcontent" id="startcontent"></a>
<h1 title="Contact">Contact</h1>
<?php
$form_block=<<<END_FORM
<form method=\"POST\" action=\" $PHP_SELF\" class=\"info_request\">
<fieldset>
<legend title="additional information request">Additional Information Request</legend>
<table id="info_request">
<tr>
<td>
<label for="firstname"><span class="red">*</span> First Name: </label></td>
<td>
<input id="firstname" name="firstname" type="text" value="$_POST ['firstname']  />
</td>
</tr>
<tr>
<td>
<label for="lastname"><span class="red">*</span> Last Name:</label></td>
<td>
<input id="lastname" name="lastname" type="text" value="$_POST ['lastname']  />
</td>
</tr>
<tr>
<td>
<label for="company"><span class="red">*</span> Company: </label></td>
<td>
<input id="company" name="company" type="text" value="$_POST ['company']  /></td>
</tr>
<tr>
<td>
<label for="phone"><span class="red">*</span> Phone: </label></td>
<td>
<input  id="phone" name="phone" type="text" value="$_POST ['phone']  /></td>
</tr>
<tr>
<td>
<label for="email"><span class="red">*</span> e-mail: </label></td>
<td>
<input  id="email" name="email" type="text" value="$_POST['email']  /></td>
</tr>
<tr>
<td>
<label for="email2"><span class="red">*</span> re-enter e-mail: </label></td>
<td>
<input  id="email2" name="email2" type="text" value="$_POST['email2']  />
</td>
</tr>
<tr>
<td>
<label for="URL"> URL:</label></td>
<td>
<input id="URL" type="text" name="URL" /> </td>
</tr>
<tr>
<td>
<label for="Contact_Preference"> Best way to reach:</label></td>
<td>
<input id="Contact_Preference" type="text" name="Contact_Preference" value="$_POST['Contact_Preference']  /></td>
</tr>
<tr>
<td>
<label for="Contact_Time"> Best time to contact:</label></td>
<td>
<input id="Contact_Time" type="text" name="Contact_Time" value="$_POST['Contact_Time']  />
</td>
</tr>
<tr>
<td valign="top">
<label for="message" id="message"> message:</label></td>
<td>
<textarea name="Textarea" rows="25" cols="50">Send me a detailed message specifying what you wish to accomplish with your web site.</textarea>
<input class="submit" src="/images/submit.gif" alt="Submit" type="image" name="submit"  /> 
</td>
</tr>
</table>
</fieldset>
</form>" ;
END_FORM; //ABSOLUTELY NO SPACES BEFORE END_FORM on this line!!!!
if ($_POST[op] !="ds")	 {
	// they need to see the form
	echo "$form_block";
	} else if ($_POST[op]  == "ds")  {
		// check value of $_POST['firstname']
		if ($_POST['firstname'] == " ")  {
			$name_err = '<span class="red">Please enter your first name!</span>< /br>';
			$send = "no" ;
	}
// check value of $POST['email']
if ($_POST ['email'] == " ")  {
	$email_err ='<span class="red">Please enter your email address!</span><br />';
	$send="no";
}
if ($send != "no") {
		//it's ok to send, so build the mail
		$msg = "E-mail sent from www site\n";
		$msg .="Sender's first name:		$_POST [firstname]\n";
		$msg .="Sender's last name:		$_POST [lastname]\n";
		$msg .="Company name:		$_POST [company]\n";
		$msg .="Senders Phone number:		$_POST [phone]\n";
		$msg .="Senders email address:		$_POST [email]\n";
		$msg .="Senders email address (re-typed):		$_POST [email2]\n";
		$msg .="URL :		$_POST[URL]\n";
		$msg .="Contact_Preference" $_POST[ Contact_Preference]\n";
				$msg .="Contact_Time" $_POST[ Contact_Time]\n";
		$msg .="Message:		$_POST [message]\n\n";
		$to ="webguync@gmail.com";
		$subject ="There has been a disturbance in the force";
		$mailheaders .="From: My Web Site
		<http://www.inspired-evolution.com>\n";
		$mailheaders .="Reply-To: $_POST [email]\n";
		//send the mail
		mail ($to, $subject, $msg, $mailheaders);
		//display information to user
  echo "<p>Hola, <strong>$firstname</strong>!.<br /><br />
We have received your request for additional information, and will respond shortly.<br />
Thanks for visiting inspired-evolution.com and have a wonderful day!<br /><br />
Regards,<br /><br />
<strong>Inspired Evolution</strong></p>";

} else if ($send =="no") {
		//print error messages
		echo "$name_err";
		echo $email_err";
		echo "$message_err";
		echo "$form_block";
		}
}
?.
<p><span class="red">*</span> indicates a required field.</p>
<p></p>
<p></p>
<?php require('includes/bottom_links.inc'); ?></div>

<!-- begin footer --> 
<div id="footer">
<p class="footertag">Inspired-Evolution - Web Site: Design, Development, Marketing for Raleigh/Durham, Chapel Hill, Cary North Carolina.</p>

<?php require('includes/footer.inc'); ?>
<span class="date"><?
$last_modified = filemtime("index.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?></span>
</div>
</div>
</div>
</body>
</html>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

First, remove the slashes on line 38, you don't need them now that you're using the heredoc syntax.

Second, I'ld remove the quote/semicolumn on line 110 (</form>" ; ) as those also aren't needed.

The syntax highlight in PHP mode still look wront (notice how everything stays blue). First try fixes the two errors identified above and then we'll see what's left.
cdog
Forum Newbie
Posts: 1
Joined: Fri Jul 29, 2005 5:58 pm
Location: Gibbsville, WI

similiar problem

Post by cdog »

Hello,

I have a similiar problem, but I don't think it's about a script. I run a production web server using Fedora Core 1, with Apache 1.3.33 installed from source, with MySQL 4.1.11 and PHP 5.0.3. I did a source install, doing the instructions found here:

http://www.php.net/manual/en/install.un ... nix.apache

Everything was working fine until tonight when I tried re-compiling apache with mod_rewrite access, and now I cannot open any php page that references data pulled from a mysql database. The page I'm trying to get working is http://www.bockyn.com/bockyn/login.php, which simply shows up blank. Apache and php are installed via source, mysql is by rpm. I've tried re-installing everything, including re-installing php and apache without extra modules, and nothing works. Any ideas?

Chris
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Also, look at lines 46,53,60,65,72,78,91,97

In all cases you don't have the closing double quotes after the $_POST['foo'] variable inclusion. I don't think this would give the errors you're seeing, but it would lead to very jumbled HTML/forms at the browser's end.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

thanks for the suggestions Eric.

here is my current code with changes...

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>Inspired Evolution :: Contact</title>
<?php require('includes/meta_tags.inc'); ?>
<link rel="stylesheet" href="Gilbert.css" type="text/css" media="screen, handheld" />
</head>
<body>
<!-- begin outer wrapper div --> 
<div id="wrapper_outer">
<a class="skiplink" href="#startcontent">Skip over navigation</a>
<!-- begin header div --> 
<div id="header"><?php require('images/Rotating_Banner/rotating_banner.php'); ?></div>
<!-- top nav list --> 
<div id="navcontainer">
<ul id="navlist">
<li ><a href="About_Me.php" title="you know you want to learn more about me">About Me</a></li>
<li><a href="Skillset.php" title="I've got skillz">Skill set</a></li>
<li><a href="Hireme.php" title="I can do wonders for your web presence">Hire Me</a></li>
<li><a href="Portfolio.php" title="web sites, graphics, newsletters">Portfolio</a></li>
<li><a href="Contact.php"  title="how to get in touch with me">Contact</a></li>
<li><a href="Resume.php"  title="my beautiful resume">R&eacute;sum&eacute;</a></li>
<li><a href="Blog.php"  title="My musings on everyday life" >Blog</a></li>
<li><a href="RSS.php"  title="Syndication that is really simple" >RSS</a></li>
</ul>
</div>
<!-- inner content wrapper div --> 
<div id="wrapper_inner">
<!-- breadcrumbs div --> 
<div id="breadcrumbs"><a href="index.php" title="home link" accesskey="1">Home</a>  > >  Contact</div>
<!-- text div --> 
<div id="main_content">
<a name="startcontent" id="startcontent"></a>
<h1 title="Contact">Contact</h1>
<?php
$form_block=<<<END_FORM
<form method="POST" action=" $PHP_SELF" class="info_request">
<fieldset>
<legend title="additional information request">Additional Information Request</legend>
<table id="info_request">
<tr>
<td>
<label for="firstname"><span class="red">*</span> First Name: </label></td>
<td>
<input id="firstname" name="firstname" type="text" value="$_POST ['firstname'] " />
</td>
</tr>
<tr>
<td>
<label for="lastname"><span class="red">*</span> Last Name:</label></td>
<td>
<input id="lastname" name="lastname" type="text" value="$_POST ['lastname']"  />
</td>
</tr>
<tr>
<td>
<label for="company"><span class="red">*</span> Company: </label></td>
<td>
<input id="company" name="company" type="text" value="$_POST ['company'] " /></td>
</tr>
<tr>
<td>
<label for="phone"><span class="red">*</span> Phone: </label></td>
<td>
<input  id="phone" name="phone" type="text" value="$_POST ['phone'] " /></td>
</tr>
<tr>
<td>
<label for="email"><span class="red">*</span> e-mail: </label></td>
<td>
<input  id="email" name="email" type="text" value="$_POST['email']"  /></td>
</tr>
<tr>
<td>
<label for="email2"><span class="red">*</span> re-enter e-mail: </label></td>
<td>
<input  id="email2" name="email2" type="text" value="$_POST['email2'] " />
</td>
</tr>
<tr>
<td>
<label for="URL"> URL:</label></td>
<td>
<input id="URL" type="text" name="URL" /> </td>
</tr>
<tr>
<td>
<label for="Contact_Preference"> Best way to reach:</label></td>
<td>
<input id="Contact_Preference" type="text" name="Contact_Preference" value="$_POST['Contact_Preference'] " /></td>
</tr>
<tr>
<td>
<label for="Contact_Time"> Best time to contact:</label></td>
<td>
<input id="Contact_Time" type="text" name="Contact_Time" value="$_POST['Contact_Time'] " />
</td>
</tr>
<tr>
<td valign="top">
<label for="message" id="message"> message:</label></td>
<td>
<textarea name="Textarea" rows="25" cols="50">Send me a detailed message specifying what you wish to accomplish with your web site.</textarea>
<input class="submit" src="/images/submit.gif" alt="Submit" type="image" name="submit"  /> 
</td>
</tr>
</table>
</fieldset>
</form>
END_FORM; //ABSOLUTELY NO SPACES BEFORE END_FORM on this line!!!!
if ($_POST[op] !="ds")	 {
	// they need to see the form
	echo "$form_block";
	} else if ($_POST[op]  == "ds")  {
		// check value of $_POST['firstname']
		if ($_POST['firstname'] == " ")  {
			$name_err = '<span class="red">Please enter your first name!</span>< /br>';
			$send = "no" ;
	}
// check value of $POST['email']
if ($_POST ['email'] == " ")  {
	$email_err ='<span class="red">Please enter your email address!</span><br />';
	$send="no";
}
if ($send != "no") {
		//it's ok to send, so build the mail
		$msg = "E-mail sent from www site\n";
		$msg .="Sender's first name:		$_POST [firstname]\n";
		$msg .="Sender's last name:		$_POST [lastname]\n";
		$msg .="Company name:		$_POST [company]\n";
		$msg .="Senders Phone number:		$_POST [phone]\n";
		$msg .="Senders email address:		$_POST [email]\n";
		$msg .="Senders email address (re-typed):		$_POST [email2]\n";
		$msg .="URL :		$_POST[URL]\n";
		$msg .="Contact_Preference" $_POST[ Contact_Preference]\n";
				$msg .="Contact_Time" $_POST[ Contact_Time]\n";
		$msg .="Message:		$_POST [message]\n\n";
		$to ="webguync@gmail.com";
		$subject ="There has been a disturbance in the force";
		$mailheaders .="From: My Web Site
		<http://www.inspired-evolution.com>\n";
		$mailheaders .="Reply-To: $_POST [email]\n";
		//send the mail
		mail ($to, $subject, $msg, $mailheaders);
		//display information to user
  echo "<p>Hola, <strong>$firstname</strong>!.<br /><br />
We have received your request for additional information, and will respond shortly.<br />
Thanks for visiting inspired-evolution.com and have a wonderful day!<br /><br />
Regards,<br /><br />
<strong>Inspired Evolution</strong></p>";

} else if ($send =="no") {
		//print error messages
		echo "$name_err";
		echo $email_err";
		echo "$message_err";
		echo "$form_block";
		}
}
?.
<p><span class="red">*</span> indicates a required field.</p>
<p></p>
<p></p>
<?php require('includes/bottom_links.inc'); ?></div>

<!-- begin footer --> 
<div id="footer">
<p class="footertag">Inspired-Evolution - Web Site: Design, Development, Marketing for Raleigh/Durham, Chapel Hill, Cary North Carolina.</p>

<?php require('includes/footer.inc'); ?>
<span class="date"><?
$last_modified = filemtime("index.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?></span>
</div>
</div>
</div>
</body>
</html>
I am still getting this freakin error...

'
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.php on line 69'

what might this mean???
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Do the line numbers shown in your post equaal the reality in your script?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

OK found a few more problems. Fixing them lets it run without errors (thought lots of warnings) on my server.

1. Remove my // ABSOLUTELY NO SPACES comment. It seems to confuse the parser.
2. You need to change all of the value="$_POST['...'] " sections.
A. Remove the spaces after POST before [
B. Remove the spaces after ] before "
C. Encase the whole thing between the double quotes with { }

For example line 46 should read:

Code: Select all

<input id="firstname" name="firstname" type="text" value="{$_POST['firstname']}" />
Anytime your trying to directly inject a value from an array into a doublely quoted string or HEREDOC you should wrap it with the curly braces. There are a few times you don't need to, but its never wrong to add them and the exceptions are rare for not needing them.

That should get you to run without errors.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

thanks for the assistance Eric.(and everyone else)

I have made the changes you mentioned and now am still getting an error. The error 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.php on line 111'

the code I now have is:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>Inspired Evolution :: Contact</title>
<?php require('includes/meta_tags.inc'); ?>
<link rel="stylesheet" href="Gilbert.css" type="text/css" media="screen, handheld" />
</head>
<body>
<!-- begin outer wrapper div --> 
<div id="wrapper_outer">
<a class="skiplink" href="#startcontent">Skip over navigation</a>
<!-- begin header div --> 
<div id="header"><?php require('images/Rotating_Banner/rotating_banner.php'); ?></div>
<!-- top nav list --> 
<div id="navcontainer">
<ul id="navlist">
<li ><a href="About_Me.php" title="you know you want to learn more about me">About Me</a></li>
<li><a href="Skillset.php" title="I've got skillz">Skill set</a></li>
<li><a href="Hireme.php" title="I can do wonders for your web presence">Hire Me</a></li>
<li><a href="Portfolio.php" title="web sites, graphics, newsletters">Portfolio</a></li>
<li><a href="Contact.php"  title="how to get in touch with me">Contact</a></li>
<li><a href="Resume.php"  title="my beautiful resume">R&eacute;sum&eacute;</a></li>
<li><a href="Blog.php"  title="My musings on everyday life" >Blog</a></li>
<li><a href="RSS.php"  title="Syndication that is really simple" >RSS</a></li>
</ul>
</div>
<!-- inner content wrapper div --> 
<div id="wrapper_inner">
<!-- breadcrumbs div --> 
<div id="breadcrumbs"><a href="index.php" title="home link" accesskey="1">Home</a>  > >  Contact</div>
<!-- text div --> 
<div id="main_content">
<a name="startcontent" id="startcontent"></a>
<h1 title="Contact">Contact</h1>
<?php
$form_block=<<<END_FORM
<form method="POST" action=" $PHP_SELF" class="info_request">
<fieldset>
<legend title="additional information request">Additional Information Request</legend>
<table id="info_request">
<tr>
<td>
<label for="firstname"><span class="red">*</span> First Name: </label></td>
<td>
<input id="firstname" name="firstname" type="text" value="{$_POST['firstname']}" />
</td>
</tr>
<tr>
<td>
<label for="lastname"><span class="red">*</span> Last Name:</label></td>
<td>
<input id="lastname" name="lastname" type="text" value="{$_POST['lastname']}" />
</td>
</tr>
<tr>
<td>
<label for="company"><span class="red">*</span> Company: </label></td>
<td>
<input id="company" name="company" type="text" value="{$_POST['company']}" /></td>
</tr>
<tr>
<td>
<label for="phone"><span class="red">*</span> Phone: </label></td>
<td>
<input id="phone" name="phone" type="text" value="{$_POST['phone']}" /></td>
</tr>
<tr>
<td>
<label for="email"><span class="red">*</span> e-mail: </label></td>
<td>
<input id="email" name="email" type="text" value="{$_POST['email']}" /></td>
</tr>
<tr>
<td>
<label for="email2"><span class="red">*</span> re-enter e-mail: </label></td>
<td>
<input id="email2" name="email2" type="text" value="{$_POST['email2']}" />
</td>
</tr>
<tr>
<td>
<label for="URL"> URL:</label></td>
<td>
<input id="URL" type="text" name="URL" /> </td>
</tr>
<tr>
<td>
<label for="Contact_Preference"> Best way to reach:</label></td>
<td>
<input id="Contact_Preference" name="Contact_Preference" type="text" value="{$_POST['Contact_Preference']}" /></td>
</tr>
<tr>
<td>
<label for="Contact_Time"> Best time to contact:</label></td>
<td>
<input id="Contact_Time" name="Contact_Time" type="text" value="{$_POST['Contact_Time']}" />
</td>
</tr>
<tr>
<td valign="top">
<label for="message" id="message"> message:</label></td>
<td>
<textarea name="Textarea" rows="25" cols="50">Send me a detailed message specifying what you wish to accomplish with your web site.</textarea>
<input class="submit" src="/images/submit.gif" alt="Submit" type="image" name="submit"  /> 
</td>
</tr>
</table>
</fieldset>
</form>
if ($_POST[op] !="ds")	 {
	// they need to see the form
	echo "$form_block";
	} else if ($_POST[op]  == "ds")  {
		// check value of $_POST['firstname']
		if ($_POST['firstname'] == " ")  {
			$name_err = '<span class="red">Please enter your first name!</span>< /br>';
			$send = "no" ;
	}
// check value of $POST['email']
if ($_POST ['email'] == " ")  {
	$email_err ='<span class="red">Please enter your email address!</span><br />';
	$send="no";
}
if ($send != "no") {
		//it's ok to send, so build the mail
		$msg = "E-mail sent from www site\n";
		$msg .="Sender's first name:		$_POST [firstname]\n";
		$msg .="Sender's last name:		$_POST [lastname]\n";
		$msg .="Company name:		$_POST [company]\n";
		$msg .="Senders Phone number:		$_POST [phone]\n";
		$msg .="Senders email address:		$_POST [email]\n";
		$msg .="Senders email address (re-typed):		$_POST [email2]\n";
		$msg .="URL :		$_POST[URL]\n";
		$msg .="Contact_Preference" $_POST[ Contact_Preference]\n";
				$msg .="Contact_Time" $_POST[ Contact_Time]\n";
		$msg .="Message:		$_POST [message]\n\n";
		$to ="webguync@gmail.com";
		$subject ="There has been a disturbance in the force";
		$mailheaders .="From: My Web Site
		<http://www.inspired-evolution.com>\n";
		$mailheaders .="Reply-To: $_POST [email]\n";
		//send the mail
		mail ($to, $subject, $msg, $mailheaders);
		//display information to user
  echo "<p>Hola, <strong>$firstname</strong>!.<br /><br />
We have received your request for additional information, and will respond shortly.<br />
Thanks for visiting inspired-evolution.com and have a wonderful day!<br /><br />
Regards,<br /><br />
<strong>Inspired Evolution</strong></p>";

} else if ($send =="no") {
		//print error messages
		echo "$name_err";
		echo $email_err";
		echo "$message_err";
		echo "$form_block";
		}
}
?.
<p><span class="red">*</span> indicates a required field.</p>
<p></p>
<p></p>
<?php require('includes/bottom_links.inc'); ?></div>

<!-- begin footer --> 
<div id="footer">
<p class="footertag">Inspired-Evolution - Web Site: Design, Development, Marketing for Raleigh/Durham, Chapel Hill, Cary North Carolina.</p>

<?php require('includes/footer.inc'); ?>
<span class="date"><?
$last_modified = filemtime("index.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?></span>
</div>
</div>
</div>
</body>
</html>
question:

below the form code with the 'if' statements do, I need to encase those in curly brackets as well?

eg:

if {($_POST['firstname']} == " ") {
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

You needed to leave the
END_FORM;
between line 110 and 111. It must be the first thing on the line and nothing else. When I told you to remove the // NOTGHING ELSE ON THIS LINE comment, I meant for you to leave the END_FROM; behind, just delete the // .... part.

You don't need the curly braces in the if. Only when in double quotes or HEREDOC syntax.
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

thanks Eric,

I added back the END_FORM;

but I still get th error on line 111. Check it out at

http://www.inspired-evolution.com/Contact_Form.php

the code I have now is

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>Inspired Evolution :: Contact</title>
<?php require('includes/meta_tags.inc'); ?>
<link rel="stylesheet" href="Gilbert.css" type="text/css" media="screen, handheld" />
</head>
<body>
<!-- begin outer wrapper div --> 
<div id="wrapper_outer">
<a class="skiplink" href="#startcontent">Skip over navigation</a>
<!-- begin header div --> 
<div id="header"><?php require('images/Rotating_Banner/rotating_banner.php'); ?></div>
<!-- top nav list --> 
<div id="navcontainer">
<ul id="navlist">
<li ><a href="About_Me.php" title="you know you want to learn more about me">About Me</a></li>
<li><a href="Skillset.php" title="I've got skillz">Skill set</a></li>
<li><a href="Hireme.php" title="I can do wonders for your web presence">Hire Me</a></li>
<li><a href="Portfolio.php" title="web sites, graphics, newsletters">Portfolio</a></li>
<li><a href="Contact.php"  title="how to get in touch with me">Contact</a></li>
<li><a href="Resume.php"  title="my beautiful resume">R&eacute;sum&eacute;</a></li>
<li><a href="Blog.php"  title="My musings on everyday life" >Blog</a></li>
<li><a href="RSS.php"  title="Syndication that is really simple" >RSS</a></li>
</ul>
</div>
<!-- inner content wrapper div --> 
<div id="wrapper_inner">
<!-- breadcrumbs div --> 
<div id="breadcrumbs"><a href="index.php" title="home link" accesskey="1">Home</a>  > >  Contact</div>
<!-- text div --> 
<div id="main_content">
<a name="startcontent" id="startcontent"></a>
<h1 title="Contact">Contact</h1>
<?php
$form_block=<<<END_FORM
<form method="POST" action=" $PHP_SELF" class="info_request">
<fieldset>
<legend title="additional information request">Additional Information Request</legend>
<table id="info_request">
<tr>
<td>
<label for="firstname"><span class="red">*</span> First Name: </label></td>
<td>
<input id="firstname" name="firstname" type="text" value="{$_POST['firstname']}" />
</td>
</tr>
<tr>
<td>
<label for="lastname"><span class="red">*</span> Last Name:</label></td>
<td>
<input id="lastname" name="lastname" type="text" value="{$_POST['lastname']}" />
</td>
</tr>
<tr>
<td>
<label for="company"><span class="red">*</span> Company: </label></td>
<td>
<input id="company" name="company" type="text" value="{$_POST['company']}" /></td>
</tr>
<tr>
<td>
<label for="phone"><span class="red">*</span> Phone: </label></td>
<td>
<input id="phone" name="phone" type="text" value="{$_POST['phone']}" /></td>
</tr>
<tr>
<td>
<label for="email"><span class="red">*</span> e-mail: </label></td>
<td>
<input id="email" name="email" type="text" value="{$_POST['email']}" /></td>
</tr>
<tr>
<td>
<label for="email2"><span class="red">*</span> re-enter e-mail: </label></td>
<td>
<input id="email2" name="email2" type="text" value="{$_POST['email2']}" />
</td>
</tr>
<tr>
<td>
<label for="URL"> URL:</label></td>
<td>
<input id="URL" type="text" name="URL" /> </td>
</tr>
<tr>
<td>
<label for="Contact_Preference"> Best way to reach:</label></td>
<td>
<input id="Contact_Preference" name="Contact_Preference" type="text" value="{$_POST['Contact_Preference']}" /></td>
</tr>
<tr>
<td>
<label for="Contact_Time"> Best time to contact:</label></td>
<td>
<input id="Contact_Time" name="Contact_Time" type="text" value="{$_POST['Contact_Time']}" />
</td>
</tr>
<tr>
<td valign="top">
<label for="message" id="message"> message:</label></td>
<td>
<textarea name="Textarea" rows="25" cols="50">Send me a detailed message specifying what you wish to accomplish with your web site.</textarea>
<input class="submit" src="/images/submit.gif" alt="Submit" type="image" name="submit"  /> 
</td>
</tr>
</table>
</fieldset>
</form>
END_FORM; 
if ($_POST[op] !="ds")	 {
	// they need to see the form
	echo "$form_block";
	} else if ($_POST[op]  == "ds")  {
		// check value of $_POST['firstname']
		if ($_POST['firstname'] == " ")  {
			$name_err = '<span class="red">Please enter your first name!</span>< /br>';
			$send = "no" ;
	}
// check value of $POST['email']
if ($_POST ['email'] == " ")  {
	$email_err ='<span class="red">Please enter your email address!</span><br />';
	$send="no";
}
if ($send != "no") {
		//it's ok to send, so build the mail
		$msg = "E-mail sent from www site\n";
		$msg .="Sender's first name:		$_POST [firstname]\n";
		$msg .="Sender's last name:		$_POST [lastname]\n";
		$msg .="Company name:		$_POST [company]\n";
		$msg .="Senders Phone number:		$_POST [phone]\n";
		$msg .="Senders email address:		$_POST [email]\n";
		$msg .="Senders email address (re-typed):		$_POST [email2]\n";
		$msg .="URL :		$_POST[URL]\n";
		$msg .="Contact_Preference" $_POST[ Contact_Preference]\n";
				$msg .="Contact_Time" $_POST[ Contact_Time]\n";
		$msg .="Message:		$_POST [message]\n\n";
		$to ="webguync@gmail.com";
		$subject ="There has been a disturbance in the force";
		$mailheaders .="From: My Web Site
		<http://www.inspired-evolution.com>\n";
		$mailheaders .="Reply-To: $_POST [email]\n";
		//send the mail
		mail ($to, $subject, $msg, $mailheaders);
		//display information to user
  echo "<p>Hola, <strong>$firstname</strong>!.<br /><br />
We have received your request for additional information, and will respond shortly.<br />
Thanks for visiting inspired-evolution.com and have a wonderful day!<br /><br />
Regards,<br /><br />
<strong>Inspired Evolution</strong></p>";

} else if ($send =="no") {
		//print error messages
		echo "$name_err";
		echo $email_err";
		echo "$message_err";
		echo "$form_block";
		}
}
?.
<p><span class="red">*</span> indicates a required field.</p>
<p></p>
<p></p>
<?php require('includes/bottom_links.inc'); ?></div>

<!-- begin footer --> 
<div id="footer">
<p class="footertag">Inspired-Evolution - Web Site: Design, Development, Marketing for Raleigh/Durham, Chapel Hill, Cary North Carolina.</p>

<?php require('includes/footer.inc'); ?>
<span class="date"><?
$last_modified = filemtime("index.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?></span>
</div>
</div>
</div>
</body>
</html>
I must still have an issue(s) on line 111 somewhere!!
Post Reply