Asked  7 Months ago    Answers:  5   Viewed   48 times

I got an error:

Parse error: syntax error, unexpected end of file in the line

With this code:

<html>
    <?php
        function login()
        {
            // Login function code
        }
        if (login())
    {?>

    <h2>Welcome Administrator</h2>
    <a href="upload.php">Upload Files</a>
    <br />
    <a href="points.php">Edit Points Tally</a>

    <?php}
        else
        {
            echo "Incorrect login details. Please login";
        }
    ?>
    Some more HTML code
</html>

What's the problem?

 Answers

30

You should avoid this (at the end of your code):

{?>

and this:

<?php}

You shouldn't put brackets directly close to the open/close php tag, but separate it with a space:

{ ?>
<?php {

also avoid <? and use <?php

Tuesday, June 1, 2021
 
KHM
answered 7 Months ago
KHM
95

Check your short_open_tag setting (use <?php phpinfo() ?> to see its current setting).

Saturday, May 29, 2021
 
jcubic
answered 7 Months ago
40
$expires = time()+604800

in the function definition.

Default value can't be the result of a function, only a simple value QUoting from the manual:

The default value must be a constant expression, not (for example) a variable, a class member or a function call.

Use:

public function set($name,$value,$expires = NULL) { 
    if (is_null($expires))
        $expires = time()+604800;
    echo $expires; 
    return setcookie($name, $value, $expires); 
} 
Saturday, May 29, 2021
 
phirschybar
answered 7 Months ago
61

you forgot the closing bracket on this statement:

if (!$resp->is_valid) {
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")");
}
Saturday, May 29, 2021
 
Rocket
answered 7 Months ago
38

here is the problem

 "Additional Comments:" . $_POST["extra"] . 
 ;

should be

  "Additional Comments:" . $_POST["extra"]   ;
Tuesday, August 24, 2021
 
tika
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share