Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. /*
  3. FINAL CODE for the DATABASE-DRIVEN, PHP/MySQL VERSION of Erik's Blog
  4. */
  5.  
  6. function makePost( $title , $body )
  7. {
  8.     $output = '
  9.     <div id="post_n" class="post">
  10.         <h2>'.$title.'</h2>
  11.         <p>'.$body.'</p>
  12.     </div>
  13.     ';
  14.     return $output;
  15. }
  16.  
  17. $username = 'root';
  18. $password = '';
  19. $location = 'localhost';
  20. $database = 'blog';
  21. $cnxn = mysql_connect( $location , $username , $password );
  22. @mysql_select_db( $database ) or die( "Error selecting database" );
  23.  
  24. ?>
  25. <html>
  26. <head>
  27. </head>
  28. <body>
  29.  
  30. <h1>Erik&rsquo;s Blog</h1>
  31.  
  32. <?php
  33.  
  34. $query = "SELECT * FROM Posts ORDER BY post_id;";
  35. $results = mysql_query( $query );
  36. while( $row = mysql_fetch_assoc($results) )
  37. {
  38.     print makePost( $row['title'] , $row['body'] );
  39. }
  40.  
  41. ?>
  42.  
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement