Trouble fixing parse error, unexpected T_IF error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciaroscuro
    New Member
    • Nov 2008
    • 2

    Trouble fixing parse error, unexpected T_IF error

    Howdy -
    In setting up a registration form, I'd like to keep any correct entries on the form (make them sticky).

    The Registration Form is "included" and has the the following structure:

    Code:
    <body>
     <?php
        echo "	<p>
    
        <form action=$_SERVER[PHP_SELF] method='POST'>
           <table width='95%' border='0' cellspacing='0' cellpadding='2'> 
    
             <tr><td></td><td>Please fill in all information.</td></tr>
    	 	
              <tr><td align='right'><b>First Name:</b></td>
     	 <td><input type='text' name='FirstName' size='35' 
                    maxlength='35'  value="if (isset($_POST['FirstName']))
                         {echo $_POST['FirstName']}; "></td></tr>
    
    	
              </table>
            <input type='hidden' name='submitted' value='yes'>
          </form>
      </p> 
     ?>
    </body>
    This generates the following error message:
    parse error, unexpected T_IF, expecting ',' or ';' in /html/RegistrationFor m1.php on line 12

    How does one punctuate the "if (isset...) to provide the indicated ", or ;" the compiler is looking for?
    Would appreciate any help or suggestions.

    Thanks
    Last edited by Banfa; Nov 11 '08, 11:39 AM. Reason: Added [code]...[/code] round the code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you missed the ; in the execution block (line 34) and put it outside the brackets (just swap } and ;)
    [PHP]if (...)
    {
    echo $var; // semicolon here
    } // not here[/PHP]
    note: a proper indentation style may increase readability a lot. you may consider to separate markup and processing by first evaluating all expressions and insert the results in your markup.

    regards

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Ciaroscuro,

      your code will be better formated and easier for our experts to read if you put &#91;code]...[/code] tags round it like I have done for you now.

      Please read our posting guidelines

      Banfa
      Administrator

      Comment

      • Ciaroscuro
        New Member
        • Nov 2008
        • 2

        #4
        Dormilich & Banfa -

        Thank you for your responses. I tried changing the position of the semi-colon but that didn't change the error message. I ended up converting from a PHP echo form to a staight HTML form with <?php ...?> phrases for the

        Code:
        <form action="<?php $_SERVER[PHP_SELF];?>" method="POST">
        and

        Code:
        <tr><td align='right'><b>First Name:</b></td>
            <td><input type='text' name='FirstName' size='35'
                  maxlength='35' value="<?php if(isset($_POST['FirstName']))
          	echo $_POST['FirstName'];?>"/></td></tr>
        to get the sticky Value attribute to work.

        Still haven't figured out why the <?php echo format didn't work, but this other approach does, so I'm making forward progress again. Thanks.
        Last edited by Markus; Nov 12 '08, 11:45 AM. Reason: added # tags

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by Ciaroscuro
          Dormilich & Banfa -

          Thank you for your responses. I tried changing the position of the semi-colon but that didn't change the error message. I ended up converting from a PHP echo form to a staight HTML form with <?php ...?> phrases for the

          Code:
          <form action="<?php $_SERVER[PHP_SELF];?>" method="POST">
          and

          Code:
          <tr><td align='right'><b>First Name:</b></td>
              <td><input type='text' name='FirstName' size='35'
                    maxlength='35' value="<?php if(isset($_POST['FirstName']))
            	echo $_POST['FirstName'];?>"/></td></tr>
          to get the sticky Value attribute to work.

          Still haven't figured out why the <?php echo format didn't work, but this other approach does, so I'm making forward progress again. Thanks.
          Ciaroscuro, please pay attention to post No.3 - it makes your post a lot easier to read for our experts if you use code tags.

          Moderator.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by Ciaroscuro
            I tried changing the position of the semi-colon but that didn't change the error message.
            checked your code snippet (with subethaedit using php) and I didn't get a parser error. judging from that, the code should be running fine.

            regards

            note: could verify the error message for the original code (just if you wonder...)

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              You can't have an IF statement inside and echo statement. Won't work. Create a function that does your IF checks and then RETURNs a value.

              Code:
              value=" . some_function() . "

              Comment

              Working...