public function strona() { $strona = '<html> <head> <meta charset="UTF-8"> <title> Zadanie<?=$no?> - Forum </title> <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" > <meta http-equiv="Pragma" content="no-cache" > <link rel="stylesheet" type="text/css" href="styl.css"> </head> <body> <header> <h1>Zadanie<?=$no?> - Prosty blog </h1> </header> <nav> <a href="../" title="Strona początkowa" target="_self" >Strona początkowa</a> <?php for($n=1;$n<11;$n++): ?> <a href="../zadanie<?=$n?>/" title="Zadanie <?=$n?>" target="_self " >Zadanie <?=$n?></a> <?php endfor ?> </nav> <nav><a href="/./Zad2/index.php">Lista tematow</a></nav> <section> <article> <h1>Temat dyskusji: '.$this->nazwa.'</h1> <p>'.$this->tresc.'</p> <footer>Autor: '.$this->nick.', '.date(" G:i,F j, Y").'</footer> </article> </section> <section>'; $strona2 = $old = file_get_contents('Tematy/art'.$this->nr.'.txt'); if(!empty($_POST['autor']) and !empty($_POST['komentarz'])) { $content = "<article><div>".nl2br(htmlspecialchars($_POST['komenatrz']))."</div><footer> Autor: ".nl2br(htmlspecialchars($_POST['autor'])).", ".date(" G:i,F j, Y")."</footer></article>".$old; } file_put_contents('Tematy/art'.$this->nr.'.txt', $content); $getter = file_get_contents('Tematy/art'.$this->nr.'.txt'); echo $getter; echo $strona2; $strona3 = '<section> <form method="POST" action="'.$this->nr.'.php"> <input type="text" name="autor" placeholder="Imię autora" \><br /> <textarea name="komentarz" cols="80" rows="10" placeholder="Tutaj wpisz swoja wypowiedź" ></textarea><br /> <button type="submit" > Wyślij komentarz</button> </form> </section> <footer> <p>Zadanie 2 - Karol B. </p> </footer> </body> </html>'; return $strona.$strona2.$strona3; }
Jest to kod funkcji odpowiadającej za tworzenie z podanych danych nowego tematu, jego pliku odnośnika etc.
Jednak plik po zapisie wygląda na przykład tak :
<html> <head> <meta charset="UTF-8"> <title> Zadanie<?=$no?> - Forum </title> <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" > <meta http-equiv="Pragma" content="no-cache" > <link rel="stylesheet" type="text/css" href="styl.css"> </head> <body> <header> <h1>Zadanie<?=$no?> - Prosty blog </h1> </header> <nav> <a href="../" title="Strona początkowa" target="_self" >Strona początkowa</a> <?php for($n=1;$n<11;$n++): ?> <a href="../zadanie<?=$n?>/" title="Zadanie <?=$n?>" target="_self " >Zadanie <?=$n?></a> <?php endfor ?> </nav> <nav><a href="/./Zad2/index.php">Lista tematow</a></nav> <section> <article> <h1>Temat dyskusji: test1 </h1> <p>opis </p> <footer>Autor: autor1, 21:50,March 25, 2019</footer> </article> </section> <section><section> <form method="POST" action="0.php"> <input type="text" name="autor" placeholder="Imię autora" \><br /> <textarea name="komentarz" cols="80" rows="10" placeholder="Tutaj wpisz swoja wypowiedź" ></textarea><br /> <button type="submit" > Wyślij komentarz</button> </form> </section> <footer> <p>Zadanie 2 </p> </footer> </body> </html>
No i jak widać, kod z poczatku tam liczącą zmienną zapisał się jako <?php .. i dopiero wykonuje się w Tematy/2.php. Tego drugiego nawet nie ma, no bo wykonuje się w indexie i nic tak na prawdę nie robi. Jestem świadomy, że gdzieś tu jest błąd albo zapisu albo myślowy, ale jestem otwarty na sugestie jak to inaczej zrobić. Pozdrawiam i liczę na was !