This CMS uses MySQL databases. So what we need to do is to create a database. Well go through this step by step to make it as easy as posible:
1. Go in to your cPanel and select phpMyAdmin.
2. Write the name of your database in the input box under the text: Create new database. This database should be named like this "yourusername_name". So mine would be nqon_cms. With astahost you must have your username first (at least if your being hosted as a subdomain). We will be calling the database "your_database" in this tutorial.
Now we need to create a table where all the content should be. It is in this table we add and edit the content.
1. Im assuming your still inside phpMyAdmin, at your left you should now have the name of your database. Click it.
2. You should now get up a text that says: Create new table on database your_database. There you should fill in the name, in this tutorial we'll call it "content". It should have 4 fields
3. The first should look like this(if somethings not specified leave it as it is):
First: Field = id | Type = INT | Length/Values = 2 | Extra = auto_increment
Second: Field = page | Type = varchar | Length/Values = 20 |
Third: Field = tittle | Type = varchar | Length/Values = 30 |
Fourth: Field = content | Type = longtext
4. Then press Go or Submit or whatever it says.
The first thing that should be done is to connect to the database, this should be in the top of every page (you can use a include() for it if you like, if you dont know what im talking about its not a problem). We'll do it this way:
connect to database code
CODE
<?php
/*Change this to your settings*/
$db = "your_database";
$db_user = "yourusername";
$db_pass = "yourpassword";
$db_connect = mysql_connect("localhost", $db_user, $db_pass)
or die("Could not connect to database.");
mysql_select_db($db, $db_connect);
?>
You should change your_database to your database name. In my case it would be $db = "nqon_cmd". Username and password should be the same as your cPanel log inn password and username.
Now thats done. Its time to make a page so you can add content to the content table you created. We'll call this file addcontent.php.
addcontent.php
CODE
<html>
<head>
<title>Insert Content</title>
</head>
<body>
<?php
if(isset($_POST['insertcontent']))
{
$page = $_POST['page'];
$tittle = $_POST['tittle'];
$content = $_POST['content'];
if(!$page OR !$tittle OR !$content){
echo "Go back and fill out all fields";
}
else{
$insertcontent = "
INSERT INTO content
(page, tittle, content)
VALUES
('$page', '$tittle', '$content')
";
mysql_query($insertcontent) or die("<p><b>A fatal MySQL error occured</b>.\n<br />Query: " .
$query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
echo "Your new content page was added!";
};
}
else { echo
?>
<form method="post">
<table border="0"><tr><td width="100">
<b>page:</b></td><td>
<input type="text" name="page" size="30" maxlength="20" class="textfield" /></td></tr><tr><td>
<b>Tittle:</b></td><td>
<input type="text" name="tittle" size="30" maxlength="30" class="textfield" /></td></tr><tr><td></table>
<p>
<b>Content:</b><br>
<textarea name="content" rows="14" cols="60">
</textarea>
<p>
<input name="insertcontent" type="submit" value="Add Content!"/>
</center>
</form>
</td></tr><table>
<?php; };
?>
</body>
</html>
Make sure that you place the "connect to database code" at the very top of this page. Its important that your main page has the page value "main". The page value is how we call the content, you should not have 2 pages with the same page value. Your page value should not have spaces. The tittle value will appear in the <tittle> </tittle> tags.
Now we would like to see that content which we just added. So its time to create the index.php page.
index.php
CODE
<?php
if(!isset($page)) {
$page="main"; };
$db_query_page = mysql_query("SELECT * FROM content WHERE page='$page' ");
$data_page = mysql_fetch_array($db_query_page);
$db_query_showlinks = mysql_query("SELECT * FROM content ORDER BY id ASC");
?>
<html>
<head>
<title>
<?php echo $data_page["tittle"]; ?>
</title>
</head>
<body>
<table>
<tr>
<td valign="top">
<?php
while($data_showlinks = mysql_fetch_array($db_query_showlinks)){
echo "<a href='/?page=";
echo $data_showlinks['page'];
echo "'>» ";
echo $data_showlinks['page'];
echo "</a>";
};
?>
</td>
<td valign="top">
<?php echo $data_s["innhold"]; ?>
</td>
</tr>
</table>
</body>
</html>
Here as well you need to insert the connect to database code at the top.
Now, you might want to edit the content every once in a while, so its time to work on that file. We'll call that file editcontent.php.
editcontent.php
CODE
<html>
<head>
<title>Edit Content</title>
</head>
<body>
<?php
if(isset($_POST['editcontent']))
{
$page = $_POST['page'];
$tittle = $_POST['tittle'];
$content = $_POST['content'];
if(!$page OR !$tittle OR !$content){
echo "Go back and fill out all fields";
}
else{
$editcontent = "
UPDATE content SET page='$page' tittle='$tittle' content='$content' WHERE id='$id' ";
mysql_query($editcontent) or die("<p><b>A fatal MySQL error occured</b>.\n<br />Query: " .
$query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
echo "The page was succesfully edited!";
};
}
elseif(isset($_POST['edit'])) {
$id= $_POST['edit'];
$db_query_edit = mysql_query("SELECT * FROM content WHERE id='$id' ");
$data_edit = mysql_fetch_array($db_query_edit);
echo
?>
<form method="post" action="editcontent.php?id=<?php echo $id; ?>">
<table border="0"><tr><td width="100">
<b>page:</b></td><td>
<input type="text" name="page" value="<?php echo $data_edit['page']; ?>" size="30" maxlength="20" class="textfield" /></td></tr><tr><td>
<b>Tittle:</b></td><td>
<input type="text" name="tittle" value="<?php echo $data_edit['tittle']; ?>"size="30" maxlength="30" class="textfield" /></td></tr><tr><td></table>
<p>
<b>Content:</b><br>
<textarea name="content" rows="14" cols="60">
<?php echo $data_edit['content']; ?></textarea>
<p>
<center>
<input name="editcontent" type="submit" value="Add Content!"/>
</center>
</form>
</td></tr><table>
<?php; } else{
$db_query_showlinks = mysql_query("SELECT * FROM innhold ORDER BY id ASC");
?>
<form action="" method="post">
<select name="edit">
<?php
while($data_showlinks = mysql_fetch_array($db_query_showlinks)){
echo "<option value='";
echo $data_showlinks['id'];
echo "'>";
echo $data_showlinks['page'];
echo "</option>";
};
?>
</select>
<input type="submit" name="contentedit" value="Edit this page!" />
</form>
<?php }; ?>
</body>
</html>
Now Im tired of writing. This should work well, but it might need some final editing first. Im going to make a version of this at my homepage for your viewing pleasure.
Its most likely a bit bugged at the moment, but Im going to fix it soon, I just need to rest a bit first. Any feedback is welcome.


