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

PHP Parse Error: syntax error, unexpected T_STRING, expecting ',' or ';'

kestrel
Expert 100+
P: 1,071
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on.

Heres what i have
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['login'])) { 
  3. echo "<div id="visible">";
  4. echo "<span onclick="swapform()">Log In Form</span>";
  5. echo "</div>";
  6. echo "<div id="theform" style="visibility: hidden">";
  7. echo "<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">";
  8. echo "<input type="text" value="Site Name" /><br />";
  9. echo "<input type="submit" value="rub a dub" />";
  10. echo "</form>";
  11. echo "</div>"; 
  12. }
  13. ?>
  14.  
and my error message is
Expand|Select|Wrap|Line Numbers
  1. Parse error:  syntax error, unexpected T_STRING, expecting ',' or ';' in /www/110mb.com/t/h/e/j/e/t/p/a/thejetpage/htdocs/test/index.php on line 24
Line 24 is line 4 up there.

Is there anything wrong there? or is some code getting mixed up with the php code?

Thanks alot

--
Kestrel
Jun 16 '07 #1
Share this Question
Share on Google+
4 Replies


P: 3
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_GET['login'])) { 
  3. echo "<div id=\"visible\">";
  4. echo "<span onclick=\"swapform()\">Log In Form</span>";
  5. echo "</div>";
  6. echo "<div id=\"theform\" style=\"visibility: hidden\">";
  7. echo "<form action=\"<?php echo $_SERVER['PHP_SELF']; ?>\" method=\"post\">";
  8. echo "<input type=\"text\" value=\"Site Name\" /><br />";
  9. echo "<input type=\"submit\" value=\"rub a dub\" />";
  10. echo "</form>";
  11. echo "</div>"; 
  12. }
  13. ?>
  14.  
The problem here looks like its a double quote conflict. You need to escape the double quotes with a backslash like this \", when they're in the string. The above version of your code should work. However, unless u're evalling this later on.. you'll get a html error when the <?php echo line is read... For that line I'd do this:
Expand|Select|Wrap|Line Numbers
  1. eval ("<form action=\""<?php echo $_SERVER['PHP_SELF']; ?>"\" method=\"post\">");
  2.  
Haven't checked that though, but you get the idea. My recent regex adventures with the e modifier may have confused my general eval syntax a little.

Good luck!
Jun 16 '07 #2

P: 3
Sorry. Eval code for line 7 of your orignal code should be:
Expand|Select|Wrap|Line Numbers
  1. eval ('?><form action="<?php echo $_SERVER[\'PHP_SELF\']; ?>" method="post">');
  2.  
Use the single quotes to avoid a whitespace and T_ error. Translates the string as being literal. Also, you'll need to comment out the single quotes in that form 'PHP_SELF', so that it reads \'PHP_SELF\'.

I can confirm that the above works...
Jun 16 '07 #3

pbmods
Expert 5K+
P: 5,821
Try this instead:
Expand|Select|Wrap|Line Numbers
  1. "<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
Or better yet:
Expand|Select|Wrap|Line Numbers
  1. echo <<<EOT
  2. <div id="visible">
  3. <span onclick="swapform()">Log In Form</span>
  4. </div>
  5. <div id="theform" style="visibility: hidden">
  6. <form action="$_SERVER[PHP_SELF]" method="post">
  7. <input type="text" value="Site Name" /><br />
  8. <input type="submit" value="rub a dub" />
  9. </form>
  10. </div>
  11. EOT;
  12.  
http://www.php.net/manual/en/languag...syntax.heredoc

Remember that anything you echo goes straight to the browser, so putting PHP code in an echo statement won't cause it to get executed.
Jun 17 '07 #4

kestrel
Expert 100+
P: 1,071
Thank you so much. I was ripping my hair out over this problem. I dont do php all that offen, and im about as good at php as Shaq is at free throw shooting. Anyways, thanks for your help guys.

-
Kestrel
Jun 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.