Hi,
ich habe ein Problem wo ich selber gar nicht mehr weiter weiß und total verwirrt bin. Ich habe etwas geschrieben wo man etwas Posten kann und ein Kommentar ablassen kann. Mit dem Posten usw hat alles super geklappt. Das einzigste Problem ist mit dem Kommentar.
Folgende Probleme/Fragen:
1. Kommentar (Text-Eingabe) = string(0)
2. Wenn ich etwas Posten möchte bei der Post-Id 2 dann macht er automatisch das ich die Post-ID 6 Kommentiere/etwas einfüge.
Im Video sieht man das ich oben was Poste. Das ist die Post-Id 2. Sobald ich da auf Comment klicke scheint unten wenn ich weiter scrolle auf der POST-Id der Eintrag: Erfolg.
Hier mal ein Video damit ihr mal ein kleines Bild davon habt.
Code:
PHP Code:
<?php
if($stmt = $pdo->prepare("SELECT
id,
username,
image,
im_type,
image_ordner,
u_post.p_id AS p_id,
u_post.u_id,
u_post.p_like,
u_post.p_heart,
u_post.post,
u_post.date,
comments.p_id,
comments.u_id,
comments.comment
FROM user
JOIN u_post ON u_post.u_id = user.id
LEFT JOIN comments ON comments.p_id = u_post.p_id
ORDER BY date DESC")) {
if(!$stmt->execute()) {
print_r($stmt->errorInfo());
}
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
?>
<section class="user_post_top_left">
<ul>
<li class="imgbox"><?php echo '<img src="data:image/' . $row['im_type'] . ';base64,' . base64_encode($row['image']) . '"/>'; ?></li>
<li><h2><?php echo $row['username']; ?></h2></li>
</ul>
</section>
<section class="user_post_time">
<p><time><small><?php echo $row['date']; ?></small></time></p>
</section>
</section>
<section class="user_post_index">
<p><?php echo $row['post']; ?></p>
<p><?php echo '<img src="'.$row['image_ordner'].'">'; ?></p>
<p><?php echo $row['comment']; ?>
<span class="user_set_value_right">
<button type="button" class="like_set"><i class="fa fa-thumbs-o-up" aria-hidden="true"></i></button><small><a href="#"><?php echo $row['p_like']; ?></a></small> <button type="button" class="heart_set"><i class="fa fa-heart-o" aria-hidden="true"></i></button><small><a href="#"><?php echo $row['p_heart']; ?></a></small>
</span>
<span class="user_set_value_left">
<form action="" method="POST">
<?php
if(isset($_POST['send_comment'])) {
$comment = $_POST['comment_msg'];
var_dump($comment);
var_dump($row['p_id']);
var_dump($_SESSION['id']);
if($insert = $pdo->prepare("INSERT INTO comments (p_id, u_id, comment) VALUES (?, ?, ?)")) {
$insert->BindValue(1, $row['p_id']);
$insert->BindValue(2, $_SESSION['id']);
$insert->BindValue(3, $comment);
if(!$insert->execute()) {
print_r($insert->errorInfo());
} else {
echo 'erfolg';
}
}
}
?>
<input type="text" name="comment_msg">
<input type="submit" name="send_comment" value="Comment">
</span>
</section>
<?php
}
}
?>
PS: Kann auch gerne Bezahlen falls jemand mir es vollständig erklären möchte und mir auch dabei helfen kann das es funktioniert.