我知道这个话题已经存在:Link,但这个答案对我没有帮助。 我有一个公式,如果我重新加载页面,公式将再次发送相同的。现在我写了Question。这是我现在的代码文件:
<?php
$article_id = $_GET['post'];
if(isset($_REQUEST['submit'])){
$article_id = $_GET['post'];
$name = $_POST['name'];
$nachricht = $_POST['nachricht'];
$aufgabe = $_POST['aufgabe'];
$random = $_POST['random'];
$successfull = FALSE;
$error_message_empty = "";
$counter = 0;
if(empty($name)){
$successfull = FALSE;
$error_message_empty = $error_message_empty . "<li>Name</li>";
$counter++;
}
if(empty($nachricht)){
$successfull = FALSE;
$error_message_empty = $error_message_empty . "<li>Nachricht</li>";
$counter++;
}
if(empty($aufgabe)){
$successfull = FALSE;
$error_message_empty = $error_message_empty . "<li>Spamschutz</li>";
$counter++;
}
else{
$sql = "SELECT * FROM captcha WHERE captcha_id='".$random."'";
$result = mysqli_query($db, $sql);
while($row=mysqli_fetch_assoc($result)){
if(!($row['captcha_solution'] == $aufgabe)){
$successfull = FALSE;
$error_message_empty = $error_message_empty . "<li>Spamschutz</li>";
$counter++;
}
}
}
if($counter != 0){
}
else{
$successfull = TRUE;
}
if($successfull == TRUE){
$eintrag = "INSERT INTO comments (comment_author, comment_date, comment_message, comment_post_id) VALUES ('$name', NOW(), '$nachricht', '$article_id')";
$eintragen = mysqli_query($db, $eintrag);
header('Location: index.php'); // ERROR MESSAGE
exit;
}
if(!(empty($error_message_empty))){
$error_message_empty = "<ol class='contact-form_error-ol'>".$error_message_empty;
$error_message_empty = $error_message_empty . "</ol>";
}
}
?>
<div class="section-head">
<?php
$select = $_GET['post'];
$sql = "SELECT * FROM posts WHERE post_id='".$select."'";
$result=mysqli_query($db,$sql);
while($row=mysqli_fetch_assoc($result)){
$sql2 = "SELECT * FROM categories";
$result2=mysqli_query($db,$sql2);
while($row2=mysqli_fetch_assoc($result2)){
if($row['post_categorie'] == $row2['categorie_id']){
echo "<p>Der ausgewählte Beitrag befindet sich in der Kategorie: <a href='index.php?categorie=$row2[categorie_id]' class='link'>$row2[categorie_name]</a></p>";
}
}
}
?>
</div>
<div class="section-body">
<?php
$sql = "SELECT * FROM posts WHERE post_id='".$select."'";
$result = mysqli_query($db, $sql);
$counter = 1;
while($row=mysqli_fetch_assoc($result)){
echo "<article>";
echo "<a class='article-title'>$row[post_title]</a>";
echo "<br>";
$d = date_create($row['post_date']);
$datum = $d->format('j.m.Y \u\m H:i \U\h\r');
echo "<a class='article-author-date'>geschrieben von $row[post_author] am $datum</a>";
echo "<br>";
echo "<br>";
echo "<p class='article-message'>$row[post_message]</p>";
echo "<div class='article-div-image'>";
$counter2 = 1;
for($i = 1; $i <= 4; $i++){
if($row['post_image_'.$i] != "0"){
if($counter2 % 2 == 0){
echo '<a data-lightbox="image-'.$counter.'" href="upload/'.$row['post_image_'.$i].'" class="wow"><img src="upload/'.$row['post_image_'.$i].'" class="article-image"></a>';
$counter2 = 0;
}
else{
echo '<a data-lightbox="image-'.$counter.'" href="upload/'.$row['post_image_'.$i].'" class="wow"><img src="upload/'.$row['post_image_'.$i].'" class="article-image margin-right"></a>';
}
}
$counter2++;
}
echo "</div>";
if($counter != mysqli_num_rows($result)){
echo "<hr>";
}
$counter++;
echo "</article>";
}
?>
<hr>
<article>
<a class="article-title">Hinterlasse doch ein Kommentar</a><br>
<a>Alle unten aufgelisteten Felder müssen ausgefüllt werden.</a>
<?php
if(!(empty($error_message_empty))){
echo "<div class='contact-form-error'>";
echo "Folgende Felder wurden nicht korrekt ausgefüllt: <br>";
echo $error_message_empty."<br>";
echo "Nach der Behebung der oben aufgelisteten Fehler, versuchen Sie es erneut.";
echo "</div>";
}
else if(!(empty($error_spam))){
echo "<div class='contact-form-error'>";
echo $error_spam;
echo "</div>";
}
else if(isset($successfull)){
if($successfull == TRUE){
echo "<div class='contact-form-success'>";
echo "Der Kommentar wurde erfolgreich erstellt!";
echo "</div>";
}
}
?>
<form class="contact-formular" action="index.php?post=<?php echo $article_id ?>" method="POST">
<a class="article-input-a">Name:</a><br><input name="name" type="text" maxlength="30" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];}?>"><br>
<a class="article-input-a">Nachricht:</a><br><textarea name="nachricht"><?php if(isset($_POST['nachricht'])){ echo $_POST['nachricht'];}?></textarea><br>
<a class="article-input-a">Captcha:</a><br>
<?php
$sql = "SELECT * FROM captcha";
$result = mysqli_query($db, $sql);
$random = rand(1, 3);
while($row=mysqli_fetch_assoc($result)){
if($random == $row['captcha_id']){
echo "<img class=contact-formular-captcha src=images/captcha/$row[captcha_task]>";
echo "<input type='hidden' name='random' value='$random' />";
}
}
?>
<br><input name="aufgabe" type="text" maxlength="30"><br>
<button class="contact-formular-button" name="submit" type="submit">Kommentar abschicken</button>
</form>
</article>
<div class="comment-box">
<?php
$select = $_GET['post'];
$sql = "SELECT * FROM comments WHERE comment_post_id='".$select."' ORDER BY comment_date DESC";
$result=mysqli_query($db,$sql);
$number = mysqli_num_rows($result);
if(empty($number)){
}
else{
echo "<hr>";
echo "<a class='article-title'>Bereits erstelle Kommentare</a><br>";
while($row=mysqli_fetch_assoc($result)){
echo "<div class='comment-only-one'>";
$d = date_create($row['comment_date']);
$datum = $d->format('j.m.Y \u\m H:i \U\h\r');
echo "Geschrieben von $row[comment_author] am $datum<br><br>";
echo "$row[comment_message]<br>";
echo "</div>";
}
}
?>
</div>
</div>
以下是错误消息:警告:无法修改标头信息 - 已在/ users / skeptar / www /中发送的标头(在/users/skeptar/www/Website/index.php:18处开始输出)第54行的网站/ include / contant-output-one-article.html 我在代码中用 // ERROR MESSAGE 标记了一行 这是我的索引:
<!DOCTYPE HTML>
<html>
<head>
<link href="css.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
<link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<!-- Lightbox -->
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/lightbox.min.js"></script>
<link href="css/lightbox.css" rel="stylesheet" />
<meta charset="utf-8">
</head>
<body>
<?php
include "connection.php";
?>
<header>
</header>
<br>
<br><br>
<div class="wrapper">
<nav>
<ul>
<li><a href="index.php?content=news"><i class="fa fa-home"></i>Startseite</a></li>
<li><a href="index.php?content=picture-gallery"><i class="fa fa-picture-o"></i>Bildergalerie</a></li>
<li><a href="index.php?content=contact"><i class="fa fa-child"></i>Kontakt</a></li>
</ul>
</nav>
<section>
<?php
if(!(isset($_GET['content']))){
if(!(isset($_GET['categorie']))){
if(!(isset($_GET['post']))){
include "include/content-output-all-news.html";
}
else{
include "include/contant-output-one-article.html";
}
}
else{
include "include/content-output-categorie-sort.html";
}
}
else{
switch($_GET['content']){
case "news":
include "include/content-output-all-news.html";
break;
case "contact":
include "include/contact/contact-form.html";
break;
case "picture-gallery":
include "include/picture-gallery/picture-gallery.html";
break;
default:
include "include/content-output-all-news.html";
break;
}
}
?>
</section>
<aside>
<div class="aside-title no-margin-top">
Wer bin ich?
</div>
<img class="aside-thats-me" src="images/thats-me.png">
<p>
usto duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod temporinvidunt ut labore et dolore magna aliquyam erat, sed diam <a href="#" class="link">askasd</a> voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
<div class="aside-title">
Kategorien
</div>
<p>
usto duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod temporinvidunt ut labore et dolore magna aliquyam erat, sed diam <a href="#" class="link">askasd</a> voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p>
<br>
<br>
<?php
include 'include/aside-output-categories.html';
?>
</aside>
<div class="both"></div>
<footer>
<ul>
<li><a href="#"><i class="fa fa-info"></i>Impressum</a></li>
<li><a href="index.php?content=contact"><i class="fa fa-child"></i>Kontakt</a></li>
<div class="both"></div>
</ul>
</footer>
</div>
</body>
</html>
以下是数据库连接的代码:
<?php
$db = mysqli_connect("localhost", "root", "", "blog");
mysqli_set_charset($db, 'utf8');
if(!$db){
die("Verbindung zur Datenbank fehlgeschlagen!");
}
?>
也许有人有个主意。
答案 0 :(得分:0)
带模板的零件在哪里
<html><head></head><body>...
?
我猜你之前已经把它发送到了浏览器?
这意味着您无法更改标题。
如果您从头开始创建站点(不使用任何cms或框架)
您可以使用以下命令启动index.php主控制器:
ob_start();
并以您想要的任何特定方式处理输出。
例如:
ob_clean();
header('Location: index.php'); // ERROR MESSAGE
根据您的帖子更改 现在我们可以看到你必须改变你的index.php以:
开头 <?php ob_start(); ?><!DOCTYPE HTML>