Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* starting point to view guestbook entries from database */
- $link2 = mysqli_connect("$db_host", "$db_user", "$db_pass", "$db_name");
- /* check connection */
- if (mysqli_connect_errno())
- {
- printf("Connect failed: %s\n", mysqli_connect_error());
- exit();
- }
- /* select needed data from database */
- $query = "SELECT id, naam, email, bericht FROM gastenboek ORDER by ID LIMIT 10";
- $result = mysqli_query($link2, $query);
- if (mysqli_num_rows($result) <= 0)
- {
- echo "Geen berichten"; // no messages
- }
- else {
- echo printf("<small>Er zijn %d berichten.</small>\n", mysqli_num_rows($result));
- while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
- echo "<BR /><BR/>
- <article>\n
- <header>\n
- <p class=\"article-info\">Geschreven op <time datetime=\"\">17 augustus, 2012</time> door <a href=\"#\"> ". $row['naam'] . "</a>";
- if(isset($_POST['submit2']))
- {
- $link_view = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
- /* check connection */
- if (mysqli_connect_errno())
- {
- printf("Connect failed: %s\n", mysqli_connect_error());
- exit();
- }
- $row['id'] = $id;
- $id = mysqli_real_escape_string($link_view, $id);
- $query2 = "DELETE FROM gastenboek WHERE id = $id";
- if (mysqli_query($link_view, $query2))
- {
- printf("%d rows deleted.\n", mysqli_affected_rows($link_view));
- }
- mysqli_close($link_view);
- }
- if (getRealIpAddr() == "127.0.0.1") {
- ?>
- <form method="POST" action="<?php echo ($_SERVER['PHP_SELF']); ?>">
- <input type="hidden" name="del_id" value="">
- <button name="submit2" style="float: right; border: none; background: none;"><img src="images/delete_.gif" /></button>
- </form>
- <?php
- } // end html form
- echo "\n</header>\n
- <div class=\"article-content\">\n
- <p> " . $row['bericht'] . "</p>\n
- </div>\n
- <hr class=\"line\">\n
- </article>\n
- <BR />\n
- ";
- } // end while loop
- } // end if statement
- mysqli_free_result($result);
- mysqli_close($link2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement