$id, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } $comments = []; while($row = $res->fetch(PDO::FETCH_ASSOC)) { $comments[] = $row; } return $comments; } function db_store_comment($nick, $email, $type, $id, $content) { global $pdo; $sql = 'INSERT INTO comments (ip, ' . get_field_name($type) . ', email, author, date, content) VALUES (:ip, :id, :email, :nick, :date, :content)'; $values = array ( ':ip' => $_SERVER['REMOTE_ADDR'], ':id' => $id, ':email' => $email, ':nick' => $nick, ':date' => time(), ':content' => $content, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } function generate_comment_field($comments, $type, $id) { $emptytexts = array( 'dir' => 'Brak komentarzy do tego katalogu, możesz być pierwszy!', 'image' => 'Brak komentarzy do tego obrazka, możesz być pierwszy!', ); $headertexts = array( 'dir' => 'Komentarze do katalogu', 'image' => 'Komentarze do obrazka', ); if (count($comments) == 0) { $output = '

' . $emptytexts[$type] . '

'; } else { $output = '

' . $headertexts[$type] . '

'; } foreach ($comments as $comment) { $output .= '
Autor: ' . htmlspecialchars($comment['author']) . ', data: ' . date('j.m.Y G:i:s', $comment['date']) . '
' . htmlspecialchars($comment['content']) . '
'; } $output .= '

Dodaj nowy komentarz

'; $output .= ''; $output .= '
Autor:
E-mail (nie pokażę go nikomu):
'; $output .= ''; $output .= '
'; return $output; } ?>