Hallo,
sobald ich ein Bild hochlade und auf Posten drücke wird der Post nicht angezeigt und die Session verschwindet direkt. Ebenso wird die U_ID 0 in der DB eingetragen.
Code:
PS: session_start() ist oben eingetragen nicht wundern warum der nicht im Code ist.
PHP
<section class="sec_index_two">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="pic" id="file" class="inputfile"/>
<label for="file"> Upload</label>
</section>
<section>
<textarea name="post" placeholder="Poste etwas..."></textarea>
</section>
<section class="sec_index_three">
<input type="hidden" name="uid"></input>
<input type="submit" name="send_post" value="Posten"></input>
<?php
if(isset($_POST['send_post'])) {
$_SESSION['id'] = $_POST['uid'];
$uid = $_SESSION['id'];
$post = $_POST['post'];
$filename = $_FILES['pic']['name'];
$size = $_FILES['pic']['size'];
$endung = strtolower(pathinfo($_FILES['pic']['name'], PATHINFO_EXTENSION));
$img = file_get_contents($_FILES['pic']['tmp_name']);
if($insert = $pdo->prepare("INSERT INTO u_post (post, u_id, image_post, img_type) VALUES (?, ?, ?, ?)")) {
$insert->BindValue(1, $post);
$insert->BindValue(2, $uid);
$insert->BindValue(3, $img);
$insert->BindValue(4, $endung);
if(!$insert->execute()) {
print_r($insert->errorInfo());
} else {
echo 'erfolgreich';
}
}
}
?>
</form>
</section>
<section class="sec_index_four">
<a href="#"><i class="fa fa-globe" aria-hidden="true"></i> <span>Öffentlich</span> <i class="fa fa-caret-down" aria-hidden="true"></i> </a>
</section>
</article>
<article id="user_post_therad">
<?php
if($stmt = $pdo->prepare("SELECT * FROM user JOIN u_post ON user.id = u_post.u_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="data:image/' . $row['img_type'] . ';base64,' . base64_encode($row['image_post']) . '"/>'; ?></p>
<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="#">271</a></small> <button type="button" class="heart_set"><i class="fa fa-heart-o" aria-hidden="true"></i></button><small><a href="#">48</a></small>
</span>
<span class="user_set_value_left">
<button type="button" class="comment_set"><i class="fa fa-comment-o" aria-hidden="true"></i></button> <a href="#">24.200 Kommentare</a>
</span>
</section>
<?php
}
}
?>
Alles anzeigen
Es wird erfolgreich ausgegeben. Alles wird in der DB gespeichert und klappt auch. Nur die U_ID ist auf 0 obwohl die u_id 12 ist in dem Fall. Es werden aber auch keine einträge ausgebeben. Hier mal 2 Bilder:
Was in der DB gespeichert wird:
Was von der DB ausgeben wird. Es wird alles ausgegeben außer wenn ich es mit einem Bild hochlade: