-3

I am trying to disable a tab (if id == 0). I get an error(in $HTML1 line):

no "li" element in list scope but a "li" end tag seen" What is the problem? why is the compiler complaining?

mostly code, mostly code

Thanks.

Edit. full HTML file here.

<html lang="eng">
<head>
    <title>Bootstrap Case</title>
</head>
<body> 

    <?php
    $fp = fopen('Benutzer.csv', 'r');
    if (!$fp) exit('datei nicht gefunden');

    while (!feof($fp)) {
    $line = fgetcsv($fp);
    if (!$line) break; // ende oder fehler
    if (!isset($line[0])) continue; // leere zeile

    list($name, $pass, $id) = $line;

    if ($name === $anmelden_name && $pass === $anmelden_passwort) {
    $gefunden = true;
    break;
    }
    }

    if ($gefunden) {
    if($id == 1){
    $HTML1 = "<li><a data-toggle='pill' href='#menu3'>Hello World</a></li>";
    $HTML2 = "<div id='menu3' class='tab-pane fade'><h3>NEUES QUIZ ERSTELLEN</h3></div>";
    }
    } else {
    $HTML1 = "";
    $HTML2 = "";
    }
    ?>

    <div class="container">

        <ul class="nav nav-pills">

            <li><a data-toggle="pill" href="#menu1">QUIZ</a></li>
            <li><a data-toggle="pill" href="#menu2">HIGHSCORE</a></li>
            <?php echo $HTML1; ?>

        </ul>

        <div class="tab-content">

            <div id="menu1" class="tab-pane fade">
                <h3>QUIZ</h3>
            </div>
            <div id="menu2" class="tab-pane fade">
                <h3>HIGHSCORE</h3>
            </div>
            <div id="menu3" class="tab-pane fade">
                <?php echo $HTML2; ?>
            </div>   
        </div>
    </div>
</body>

Cashew
  • 11
  • 6
  • 1
    ... or escape the double quotes, or use HEREDOC syntax ... I'm 99% sure this will be closed as a duplicate shortly. – CD001 Jan 19 '17 at 13:50
  • What's actually producing that error message? I would expect a PHP syntax error message instead... – David Jan 19 '17 at 13:51
  • @David Why expect a PHP syntax error ? PHP would just return the string, no matter what's inside it. – JoeriShoeby Jan 19 '17 at 13:56
  • @JoeriShoeby: Because that first block of code is full of syntax errors as a result of mis-matched quotes. Any attempt to execute that code will fail, so how can the *successful result* of that code be producing an error when there is no successful result? – David Jan 19 '17 at 13:59
  • its working in a php file. But not when I use php inside of html.... ähm its a html file with php code, and html inside of the php code – Cashew Jan 19 '17 at 14:16
  • @Cashew: What does that even mean? Where specifically is the error coming from and what is the exact code producing that error? If the error is from the resulting HTML in the browser, what is that HTML? – David Jan 19 '17 at 14:17
  • @David is marked red in netbeans. Its like HTML-file(PHP-code(HTML-code)) – Cashew Jan 19 '17 at 14:25
  • @Cashew: Is it just your IDE telling you that something *might* be wrong? Or is there an actual runtime error somewhere? When mixing multiple languages IDEs *can* be mistaken. What's the actual result of running for code? – David Jan 19 '17 at 14:27
  • @David It shows "; $HTML2 = " hello "; } } else { $HTML1 = ""; $HTML2 = ""; } ?> between the tabs – Cashew Jan 19 '17 at 14:30
  • @Cashew: If you're seeing PHP code in your browser then something is wrong. Is your PHP executing at all? If not, your server is misconfigured. If you're executing some PHP code but not other parts, maybe you're sending PHP code to your browser as a string? You definitely can't do that, web browsers don't execute PHP. – David Jan 19 '17 at 14:38
  • values of `$found` and `$id` are what exactly? and did you open/close the php tags? – Funk Forty Niner Jan 19 '17 at 14:38
  • Possible duplicate of [PHP code is not being executed, instead code shows on the page](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – Funk Forty Niner Jan 19 '17 at 14:39
  • @ Fred -ii- $found = true, $=1 – Cashew Jan 19 '17 at 14:41
  • *"It shows "; $HTML2 = " hello "; } } else { $HTML1 = ""; $HTML2 = ""; } ?> between the tabs"* - The question is getting too unclear at this point. I asked if you did open and close the php tags for the php code. Plus, are you running this off your own machine? Is a webserver/php installed? If so, how are you using this as, `http://localhost` or directly in your browser as `file:///`? There is a difference. – Funk Forty Niner Jan 19 '17 at 14:45
  • added more code. yes i did. running it on webserver with php – Cashew Jan 19 '17 at 14:45
  • running it on a uni pc. Using a Webserver. ip/~myFolders/myFile.html, php tags are cloded – Cashew Jan 19 '17 at 14:55
  • @Cashew: If you're putting PHP code in an HTML file, that could be what's confusing the IDE. It seems like the whole question is based on nothing more than a warning issued by your IDE telling you that it couldn't make sense of the HTML code. But you're writing PHP code, so that would explain why it can't make sense of it as HTML. There doesn't seem to be any actual issue here... – David Jan 19 '17 at 15:12

2 Answers2

2

Use single quotes like this and you can modify code if you want

if ($found) {
 $HTML1 = "";
 $HTML2 = "";
if($id == 1){
    $HTML1 = '<li><a data-toggle="pill" href="#menu3">Hello World</a></li>';
    $HTML2 = '<div id="menu3" class="tab-pane fade"><h3>Hello!</h3></div>';}
} 
Man Programmer
  • 5,300
  • 2
  • 21
  • 21
1

Seeing that you edited your code and using the proper quotes and given the multiple comments (by myself in order to get clarification), and this last one by the OP:

"its a .html file – Cashew"

That file needs to be .php extension if you haven't instructed your server to treat .html files as PHP and that is unknown.

You also need to run this as http://localhost/file.php if local on your machine and that a webserver and PHP are installed and properly configured.

If your code should fail, then you will need to check for errors.

which I find would be beyond the scope of the question.

Your <?php echo $HTML1; ?> and others, should be throwing you undefined variables notices and you should use a conditional statement or a ternary operator for those.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • well. I need a html file for the tabs with bootstrap, and a php file to check if $id is 1, or 0. When its 0, i need to disable a tab in the html file. Whats the best way to do this? – Cashew Jan 19 '17 at 15:19
  • @Cashew you'll need to use ajax then and that also is beyond the scope of the question/problem. That, or instruct your server to treat `.html` files as PHP or if your server supports it; include the `.html` files, or as an iframe. – Funk Forty Niner Jan 19 '17 at 15:21
  • @Cashew You're welcome. And yes, you will need to use another method. I believe the question should now be marked as solved. – Funk Forty Niner Jan 19 '17 at 15:26