0

Hello I have a problem with an onClick button when i try to echo it can someone help please

<?php
echo '<nav>';
echo    '<ul id="navigation">';
echo        '<li data-menuanchor="home" class="active"><a href="#home">Home</a></li>';
echo        '<li data-menuanchor="Competency"><a href="#Competency">Skills & Competencies</a></li>';
echo        '<li data-menuanchor="Contact"><a href="#Contact">Contact</a></li>';
echo    '</ul>';
echo '</nav>';
echo '';
echo '<div class="account">';
echo    '<button class="account-btn" onClick="location.href='Access.php'">';
echo        'Login / Register';
echo    '</button>';
echo '</div>';
?>

The error I get is

Parse error: syntax error, unexpected identifier "Access", expecting "," or ";" in file root location line 11

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Lyfe A1
  • 31
  • 7
  • 2
    Your using single quotes before Access, which clothes the string, which you started in front of – Geshode May 27 '21 at 15:37
  • Also, for readabilty, you might consider using HEREDOC syntax. It owuld allow you to create these large blocks of HTML without all the `echo` and quote issues: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc – Kinglish May 27 '21 at 15:40

2 Answers2

0

You have a quote in your string:

f='Access.php'

Change it to:

f=\'Access.php\'
newb
  • 16
  • 3
0

You missed to escape single-quotes ':

echo    '<button onClick="location.href='Access.php'">';
                                        ^          ^
echo    '<button onClick="location.href=\'Access.php\'">';

For better readable format use HEREDOC

echo <<<HTML
<nav> 
   <ul id="navigation"> 
        <li data-menuanchor="home" class="active"><a href="#home">Home</a></li>
        <li data-menuanchor="Competency"><a href="#Competency">Skills & Competencies</a></li>
        <li data-menuanchor="Contact"><a href="#Contact">Contact</a></li>
    </ul> 
 </nav> 
  
 <div class="account">' 
    <button class="account-btn" onClick="location.href='Access.php ">
        Login / Register 
    </button> 
 </div>
HTML;
XMehdi01
  • 5,538
  • 2
  • 10
  • 34