-1

I'm following a php tutorial and for some reason I keep getting an error with this block of php code. It's simple but I just can't figure out what's wrong with it. I ge this error:

The error: syntax error, unexpected 'action' (T_STRING), expecting ',' or ';'

<?php if(isset($_SESSION[‘loggedin’])){
        echo ‘<form action="postForm.php" method="post">
                <TextArea name="microBlog" id="microBlog" cols="30" rows="10">
                </TextArea>
                </br>
                <input type="submit">
        </form>’; 
}
?>
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
JulianJ
  • 1,259
  • 3
  • 22
  • 52

5 Answers5

2
<?php if(isset($_SESSION['loggedin'])){
        echo '<form action="postForm.php" method="post">
                <TextArea name="microBlog" id="microBlog" cols="30" rows="10">
                </TextArea>
                </br>
                <input type="submit">
        </form>'; 
}
?>

There is difference between backtick and single quotes.

A string literal can be specified in four different ways:

Single quoted strings will display things almost completely "as is." Variables and most escape sequences will not be interpreted. The exception is that to display a literal single quote, you can escape it with a back slash \', and to display a back slash, you can escape it with another backslash \ (So yes, even single quoted strings are parsed).

Double quoted : If the string is enclosed in double-quotes ("), PHP will interpret the following escape sequences for special characters:

Heredoc : A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation.

Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping. It shares some features in common with the SGML construct, in that it declares a block of text which is not for parsing.

For more info, click Strings

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
0

Try This

<?php if(isset($_SESSION['loggedin'])){
        echo '<form action="postForm.php" method="post">
                <TextArea name="microBlog" id="microBlog" cols="30" rows="10">
                </TextArea>
                </br>
                <input type="submit">
        </form>'; 
}
?>

You've used backticks that caused the problem.

Md. Khairul Hasan
  • 704
  • 1
  • 10
  • 21
0

Also pay attention that long strings usually wrapped like:

$str = <<<EOL
<form action="postForm.php" method="post">
    <TextArea name="microBlog" id="microBlog" cols="30" rows="10"></TextArea>
    </br>
    <input type="submit">
</form>
EOL;

echo $str;
D.Dimitrioglo
  • 3,413
  • 2
  • 21
  • 41
0

Just echo every line for itself:

<?php if(isset($_SESSION[‘loggedin’]) { 
    echo ‘<form action="postForm.php"'; method="post"> 
    echo '<TextArea name="microBlog" id="microBlog" cols="30" rows="10"></TextArea>';
    echo '<br>'; 
    echo '<input type="submit">';
    echo '</form>’; 
}
Axel
  • 568
  • 7
  • 18
0

You should use ' or " instead of ‘ or ’

nPcomp
  • 8,637
  • 2
  • 54
  • 49