How to make a blog site

Suppose you need a blog site where you want to add a new page like  wordpress then you need to follow the following tips.

All are same like my previous tutorial but we will use database.. all information will retrive from database. suppose database name is shamim and a table named by pages with three fields like as page_id, page_title, and page_desc

then   …………………………………include.php…………………………….

<?php

//connect to db
mysql_connect(“localhost”, “root”, “”)or die(“Cannot connect to the Database Server”);
mysql_select_db(“shamim”)or die(“Cannot select Database”);

?>

<head>
<title>My Tutorial</title>
<link href=”style.css” rel=”stylesheet” type=”text/css” />
</head>

<body>
<table width=”700″ border=”1″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr>
<td><?php include(“header.php”); ?></td>
</tr>
<tr>
<td><?php
//all pages will include here

if(isset($_GET[‘s’])) {    $includepage=$_GET[‘s’];}
else{$includepage    =    1;}

switch($includepage)    {

case “”:
include(“start.php”);
break;

case 1:
include(“start.php”);
break;

case 2:
include(“pages.php”);
break;

case 3:
include(“add_pages.php”);
break;

default:
include(“start.php”);
break;
}

?></td>
</tr>
<tr>
<td><?php include(“footer.php”); ?></td>
</tr>
</table>

</body>
</html>

…………………………pages.php…………………………………

<?php
$page_id    =    $_GET[‘page_id’];
$q    =    mysql_query(“SELECT * FROM pages WHERE page_id=$page_id”);
while($r=mysql_fetch_array($q))
{
echo “<h2>”.$r[‘page_title’].”</h2>”.nl2br($r[‘page_desc’]);
}

?>

………………………………… add_page.php………………………….

<h2>Add Pages </h2>
<?php
if(isset($_POST[‘Submit’]))
{
$page_title    =    $_POST[‘page_title’];
$page_desc    =    $_POST[‘page_desc’];

$q    =    mysql_query(“INSERT INTO pages(page_title,page_desc) VALUES(‘$page_title’,’$page_desc’)”);
if($q){echo “Added”;}else{echo “Sorry”;}
}

?>

<form name=”form1″ method=”post” action=””>
<table width=”400″ border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr>
<td>Page Title</td>
<td><input name=”page_title” type=”text” id=”page_title”></td>
</tr>
<tr>
<td>Page Details </td>
<td><textarea name=”page_desc” id=”page_desc”></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type=”submit” name=”Submit” value=”Submit”></td>
</tr>
</table>
</form>

…………………………header.php……………………………….

<h1 align=center>Shamim</h1>
<a href=”./”>Home</a>
<a href=”index.php?s=3″>Add Pages</a>
<?php

$q    =    mysql_query(“SELECT page_id,page_title FROM pages”);
while($r=mysql_fetch_array($q))
{
echo “<a href=index.php?s=2&page_id=”.$r[‘page_id’].”>”.$r[‘page_title’].”</a>&nbsp;&nbsp;”;
}
?>
……………………………..  footer.php…………………………….

&copy; 2010. Shamim.com

…………………….start.php…………………

<h2>Welcome</h2>

…………………………style.css………………………

body
{
font-family: Arial;
}

h1
{
color: #ff0000;
}

h2
{
color: #0000FF;
padding: 5px 0 5px 5px;
margin: 0;
}

a
{
color: #00FF00;
text-decoration: none;
}

a:hover
{
color: #ff0000;
}

…………………………………………………………………………………………………….

sorry i couldn’t write details for unsufficient time.. I will try to details i just paste code from editor if you face any problem then mail me thanks now start to do it..

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: