-3
<div class="border">
    <a href="index.html"><img class="Logo" src="img/Logo.png" alt="Logo"></a>
      <form class="" action="index.php" method="post">
        <input id="searchbar" type="text" name="searchbar" placeholder="Search...">
      </form>
      <?php
        if (isset($_SESSION["useruid"]))  {
          echo "<button class="borderbutton" id="signupbutton" title="Press to go to profile page" onclick="location.href='profile.php'">Profile</button>";
          echo "<button class="borderbutton" id="loginbutton" title="Press to logout" onclick="location.href='includes/logout-inc.php'">Log out</button>";
        }
        else {
          echo "<button class="borderbutton" id="signupbutton" title="Press to sign up" onclick="location.href='signup.php'">Sign up</button>";
          echo "<button class="borderbutton" id="loginbutton" title="Press to login" onclick="location.href='login.php'">Login</button>";
        }
      ?>
</div>

Should I use 'include' instead and link to a new page? I feel like there should be some way to make this work with the 'echo' command.

4127157
  • 1,438
  • 2
  • 15
  • 28
  • 2
    No need to echo _static_ text in the first place. https://www.php.net/manual/en/language.basic-syntax.phpmode.php – CBroe Aug 25 '21 at 08:27
  • 1
    you've got double-quotes inside a double-quoted string. So obviously PHP is going to get confused about where the string really ends. Either single-quote the string, or use single quotes _inside_ the string, or just don't use echo at all, as CBroe suggested. – ADyson Aug 25 '21 at 08:35
  • `Should I use 'include' instead and link to a new page? `....that has nothing to do with it and wouldn't solve anything. – ADyson Aug 25 '21 at 08:35
  • For future reference: [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – ADyson Aug 25 '21 at 08:36

1 Answers1

2

Couple of issues... If you do want to use echo statements, your text you are echoing needs to be wrapped in quotes to make one string. As you are using double quotes in your html you can do this with single quotes like

echo '<button class="borderbutton" id="signupbutton" title="Press to go to profile page" onclick="location.href=\'profile.php\'">Profile</button>';

Using backslash to escape the single quotes in your string.

However echo statements aren't needed at all in this instance as your only printing static text. So you can do:

<div class="border">
    <a href="index.html"><img class="Logo" src="img/Logo.png" alt="Logo"></a>
      <form class="" action="index.php" method="post">
        <input id="searchbar" type="text" name="searchbar" placeholder="Search...">
      </form>
      <?php
        if (isset($_SESSION["useruid"]))  { ?>
          <button class="borderbutton" id="signupbutton" title="Press to go to profile page" onclick="location.href='profile.php'">Profile</button>;
          <button class="borderbutton" id="loginbutton" title="Press to logout" onclick="location.href='includes/logout-inc.php'">Log out</button>
       <?php }
        else { ?>
          <button class="borderbutton" id="signupbutton" title="Press to sign up" onclick="location.href='signup.php'">Sign up</button>
         <button class="borderbutton" id="loginbutton" title="Press to login" onclick="location.href='login.php'">Login</button>
       <?php }
      ?>
</div>
DevWithZachary
  • 3,545
  • 11
  • 49
  • 101
  • 1
    Nice answer. I'd also mention PHP's [alternative syntax](https://www.php.net/manual/en/control-structures.alternative-syntax.php) like `if (...): ... elseif (...): ... endif;`, where you can leave out the curly brackets. I prefer to use this for static text. – Oskar Grosser Aug 25 '21 at 09:13