A syntax error occurs

Question:
Hello, I encountered an error like this in PHP, how should I deal with it?

Parse error: syntax error, unexpected token "if" in /home/runner/php/ad/1/2/3/4/server.php on line 10

The code will be this.

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>Server console</title>
</head>
<body>
  <?php
  $logincookie = $_COOKIE
  if ($logincookie == namae) {

  } elseif ($logincookie == null) {
    
  } else {
      echo "Sorry, some error prevented access. Please log in again.";
  }
  echo"<h1>Welcome to the Server console.</h1>";
  echo "<a href="."logout.html".">Logout</a>";
   echo "<a href="."https://e887b4f9-57f7-4ba1-b25f-5a1633f91c06-00-5n6j13l7d88u.sisko.replit.dev/ad/1/2/3/4/5/6/os-% 20release.php"."> <br> os-
    release"
  ?>
</body>
</html>

What is wrong?
Repl link:

code snippet

screenshot

Seems like it doesn’t know how to handle the if statement on line 10, double check your syntax and formatting perhaps?

There are two mistakes in your code

You are missing an end semicolon on line 9
your variable $logincookie is expecting a string value of “namae” and needs to be enclosed with quotation marks

Below is the corrected code

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>Server console</title>
</head>
<body>
  <?php
  $logincookie = $_COOKIE;
  if ($logincookie == "namae") {

  } elseif ($logincookie == null) {

  } else {
      echo "Sorry, some error prevented access. Please log in again.";
  }
  echo"<h1>Welcome to the Server console.</h1>";
  echo "<a href="."logout.html".">Logout</a>";
   echo "<a href="."https://e887b4f9-57f7-4ba1-b25f-5a1633f91c06-00-5n6j13l7d88u.sisko.replit.dev/ad/1/2/3/4/5/6/os-% 20release.php"."> <br> os-
    release"
  ?>
</body>
</html>
2 Likes