Page 1 of 1

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

Posted: Wed Jun 15, 2005 1:51 pm
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!

Posted: Wed Jun 15, 2005 1:54 pm
by hawleyjr
Remove the } from line 6 and 4:

Code: Select all

echo $_POST['country']};

Posted: Wed Jun 15, 2005 2:02 pm
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.

Posted: Wed Jun 15, 2005 2:08 pm
by ol4pr0
Your missing something

Code: Select all

} else {
  echo '<option value="United States" selected>United States</option>\n';
} < = missing

Posted: Wed Jun 15, 2005 2:09 pm
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>'

Posted: Wed Jun 15, 2005 2:10 pm
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.