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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kestrel
    Recognized Expert Top Contributor
    • Jul 2006
    • 1071

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

    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
    [code=php]
    <?php
    if(isset($_GET['login'])) {
    echo "<div id="visible">" ;
    echo "<span onclick="swapfo rm()">Log In Form</span>";
    echo "</div>";
    echo "<div id="theform" style="visibili ty: hidden">";
    echo "<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">" ;
    echo "<input type="text" value="Site Name" /><br />";
    echo "<input type="submit" value="rub a dub" />";
    echo "</form>";
    echo "</div>";
    }
    ?>
    [/code]
    and my error message is
    Code:
    [b]Parse error[/b]:  syntax error, unexpected T_STRING, expecting ',' or ';' in [b]/www/110mb.com/t/h/e/j/e/t/p/a/thejetpage/htdocs/test/index.php[/b] on line [b]24[/b]
    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
  • skippychalmers
    New Member
    • Jun 2007
    • 3

    #2
    [code=php]
    <?php
    if(isset($_GET['login'])) {
    echo "<div id=\"visible\"> ";
    echo "<span onclick=\"swapf orm()\">Log In Form</span>";
    echo "</div>";
    echo "<div id=\"theform\" style=\"visibil ity: hidden\">";
    echo "<form action=\"<?php echo $_SERVER['PHP_SELF']; ?>\" method=\"post\" >";
    echo "<input type=\"text\" value=\"Site Name\" /><br />";
    echo "<input type=\"submit\" value=\"rub a dub\" />";
    echo "</form>";
    echo "</div>";
    }
    ?>
    [/code]

    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:
    Code:
    eval ("<form action=\""<?php echo $_SERVER['PHP_SELF']; ?>"\" method=\"post\">");
    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!

    Comment

    • skippychalmers
      New Member
      • Jun 2007
      • 3

      #3
      Sorry. Eval code for line 7 of your orignal code should be:
      [code=php]
      eval ('?><form action="<?php echo $_SERVER[\'PHP_SELF\']; ?>" method="post">' );
      [/code]
      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...
      Last edited by skippychalmers; Jun 16 '07, 09:48 PM. Reason: spelling mistake.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Try this instead:
        [code=php]"<form action=\"$_SERV ER[PHP_SELF]\" method=\"post\" >[/code]

        Or better yet:
        [code=php]
        echo <<<EOT
        <div id="visible">
        <span onclick="swapfo rm()">Log In Form</span>
        </div>
        <div id="theform" style="visibili ty: hidden">
        <form action="$_SERVE R[PHP_SELF]" method="post">
        <input type="text" value="Site Name" /><br />
        <input type="submit" value="rub a dub" />
        </form>
        </div>
        EOT;
        [/code]



        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.
        Last edited by pbmods; Jun 17 '07, 12:47 AM. Reason: Added link

        Comment

        • kestrel
          Recognized Expert Top Contributor
          • Jul 2006
          • 1071

          #5
          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

          Comment

          Working...