Sticky form, unexpected $ on the last line of my html code

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

Post Reply
purefusion
Forum Newbie
Posts: 6
Joined: Wed Jun 15, 2005 1:21 pm

Sticky form, unexpected $ on the last line of my html code

Post by purefusion »

I'm building a sticky form with a country selection menu. What I want to do is have "United States" selected unless they've submitted a form with errors. In that case, I want their last answser to be posted in the reloaded form as the selected option.

What I need is for someone to check if the syntax of the following code is correct because I get an error code that says:

Parse error: parse error, unexpected $ in /pages/sample_holograms_page1.php on line 714

Line 714 is the last line of html in the php document, and it's the line under the closing </html> tag, but there's nothing on it. This code is from lines 312-322. When I remove these lines from the document, the form works error free.

Code: Select all

<?php 
if (isset($_POST['country'])) {
  echo '<option value="';
  echo $_POST['country'];
  echo '" selected>';
  echo $_POST['country'];
  echo '"</option>\n';
  echo '<option value="United States">United States</option>\n';
} else {
  echo '<option value="United States" selected>United States</option>\n';
?>
I think it may have to do with the global vars, but I'm not sure. Any help is appreciated greatly!
Last edited by purefusion on Wed Jun 15, 2005 2:04 pm, edited 2 times in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Remove the } from line 6 and 4:

Code: Select all

echo $_POST['country']};
purefusion
Forum Newbie
Posts: 6
Joined: Wed Jun 15, 2005 1:21 pm

Post by purefusion »

Sorry, that was a typo in the post. I edited the post, so there is the exact code that is giving me the problems.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Your missing something

Code: Select all

} else {
  echo '<option value="United States" selected>United States</option>\n';
} < = missing
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

The only things I see wrong is the missing } at the end. But that would cause a different error.

Try echoing it out like:

Code: Select all

$str = '<option value="' . $_POST['country'] . '" selected>' . $_POST['country'] . '</option>'
purefusion
Forum Newbie
Posts: 6
Joined: Wed Jun 15, 2005 1:21 pm

Post by purefusion »

ol4pr0 wrote:Your missing something

Code: Select all

} else {
  echo '<option value="United States" selected>United States</option>\n';
} < = missing
Thanks olpro, I just noticed that! It's always something small :)
Thanks for the help! Works fine now.
Post Reply