PHP Blog: Index.php


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $db = mysql_connect("localhost", "username", "password") or die("Could not connect to database.");
  4. if(!$db)
  5. die("no db");
  6. if(!mysql_select_db("blog",$db))
  7. die("No database selected.");
  8.  
  9. $id = $_GET['id'];
  10.  
  11. $fid="SELECT * from blog where blogid='$id'";
  12. $fid2=mysql_query($fid) or die("Could not get data");
  13. $fid3=mysql_fetch_array($fid2);
  14.  
  15. $blogid = $fid3['blogid'];
  16.  
  17. if ($blogid > 0.1)
  18. echo "";
  19. else
  20. header("Location: index.php");
  21. ?>
  22.  
  23. <?php
  24.  
  25. //mysql database connection
  26. $dbhost='Database Host';
  27. $dbuser='Your Username';
  28. $dbpass='Your Password';
  29. $dbtable='Your Table Name';
  30.  
  31. mysql_connect("$dbhost", "$dbuser", "$dbpass") or die("Could not connect.");
  32. mysql_select_db("$dbtable") or die("Table could not be selected.");
  33.  
  34. $id=$_GET['id'];
  35.  
  36. $fblogid=mysql_query("SELECT * from blog where blogid='$id'") or die("Could not load the entries.");
  37. $fblogid2=mysql_fetch_array($fblogid);
  38.  
  39. $message=($fblogid2['message']);
  40. $message=nl2br($message);
  41. $date=($fblogid2['date']);
  42.  
  43. print "";
  44.  
  45. $fshow=mysql_query("Select * from blog where blogid='$id' order by blogid asc") or die("Could not find blog posts.");
  46. while($fshow2=mysql_fetch_array($fshow))
  47.  
  48. {
  49.  
  50. $message=($fshow2['message']);
  51. $message=nl2br($message);
  52.  
  53. print "$message<br/><hr><p align='right'>Posted on: $date</p><br>";
  54.  
  55. }
  56. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.