Advertisement
Guest User

Untitled

a guest
Aug 26th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. /* starting point to view guestbook entries from database */
  2. $link2 = mysqli_connect("$db_host", "$db_user", "$db_pass", "$db_name");
  3.  
  4. /* check connection */
  5. if (mysqli_connect_errno())
  6. {
  7.     printf("Connect failed: %s\n", mysqli_connect_error());
  8.     exit();
  9. }
  10.  
  11. /* select needed data from database */
  12. $query = "SELECT id, naam, email, bericht FROM gastenboek ORDER by ID LIMIT 10";
  13. $result = mysqli_query($link2, $query);
  14.  
  15. if (mysqli_num_rows($result) <= 0)
  16. {
  17.     echo "Geen berichten"; // no messages
  18. }
  19.    
  20. else {
  21.     echo printf("<small>Er zijn %d berichten.</small>\n", mysqli_num_rows($result));
  22.     while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
  23.  
  24.         echo    "<BR /><BR/>
  25.                 <article>\n
  26.                 <header>\n
  27.                 <p class=\"article-info\">Geschreven op <time datetime=\"\">17 augustus, 2012</time> door <a href=\"#\"> ". $row['naam'] . "</a>";
  28.  
  29.                 if(isset($_POST['submit2']))
  30.                 {
  31.                
  32.                     $link_view = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
  33.  
  34.                     /* check connection */
  35.                     if (mysqli_connect_errno())
  36.                     {
  37.                         printf("Connect failed: %s\n", mysqli_connect_error());
  38.                         exit();
  39.                     }
  40.                    
  41.                     $row['id'] = $id;
  42.                     $id = mysqli_real_escape_string($link_view, $id);
  43.                    
  44.                     $query2 = "DELETE FROM gastenboek WHERE id = $id";
  45.                    
  46.                     if (mysqli_query($link_view, $query2))
  47.                     {
  48.                         printf("%d rows deleted.\n", mysqli_affected_rows($link_view));
  49.                     }
  50.                     mysqli_close($link_view);
  51.                 }
  52.    
  53.                
  54.                        
  55.                 if (getRealIpAddr() == "127.0.0.1")  {
  56.                
  57.                 ?>
  58.  
  59.                 <form method="POST" action="<?php echo ($_SERVER['PHP_SELF']); ?>">
  60.                 <input type="hidden" name="del_id" value="">
  61.                 <button name="submit2" style="float: right; border: none; background: none;"><img src="images/delete_.gif" /></button>
  62.                 </form>
  63.  
  64.                 <?php
  65.                 } // end html form
  66.                                    
  67.                 echo    "\n</header>\n
  68.                         <div class=\"article-content\">\n
  69.                         <p> " . $row['bericht'] . "</p>\n
  70.                         </div>\n
  71.                         <hr class=\"line\">\n
  72.                         </article>\n
  73.                         <BR />\n
  74.                         ";
  75.                        
  76.                        
  77.  
  78.             } // end while loop
  79. } // end if statement
  80.  
  81.  
  82. mysqli_free_result($result);
  83.  
  84. mysqli_close($link2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement