Nov 21, 2009
Pages: 1, 2

Creating A Content Managing System - Using MySQL

free web hosting

Read Latest Entries..: (Post #15) by pyost on Mar 10 2007, 10:07 AM.
Could you copy the whole error?
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Creating A Content Managing System - Using MySQL

Nqon
This tutorial is for beginners that know some php and know the basics of MySQL. I will tell you how to make a simple Content Managing System. A Content Managing System is a way of editing and adding your content using your browser, so you dont have to go trough ftp all the time.

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[tab][/tab]= "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'];


[tab][/tab]if(!$page OR !$tittle OR !$content){
 echo "Go back and fill out all fields";
 }
[tab][/tab]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!";
[tab][/tab]};
}
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'];


[tab][/tab]if(!$page OR !$tittle OR !$content){
 echo "Go back and fill out all fields";
 }
[tab][/tab]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!";
[tab][/tab]};
}
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.

 

 

 


Comment/Reply (w/o sign-up)

Nqon
Im going through the tutorial today, is it posible for me to get some extra points for this. I mean, I wrote all those things in the code and you dont get points for that... sad.gif

Comment/Reply (w/o sign-up)

dungsport
Why? I'm so curious to know the reason, tongue.gif

Or maybe you put all those code into CODE tag and they were ignored?

Comment/Reply (w/o sign-up)

Nqon
Thats right... you dont get any points in code or quote tags. Its okey, else people quoting each other would get points, and so would people that copy some code of a page.

Comment/Reply (w/o sign-up)

rapco
Nqon, i know how to do what you explained. But there's is something i don know yet... and i would to to learn... how to create users and passwords????? do u know how?

Comment/Reply (w/o sign-up)

Nqon
What is it you cant do with users and passwords? If you know how to do what I explained it shouldnt be any problems beside the cookie/session problem.

If you know how to add a new row to a table, and how to edit it it should not be any problem to add a user and let him change his profil. I made an excellent userdatabase on my site that allows me to have admin features, and several different userlevels, so only some people can visit sensitive pages (nothing illigal, just tactics for my clan biggrin.gif ).

Anyway, if your problem is creating a userdatabase you obviously dont know what I tryed to explain here, but if your problem is to use cookies I could write a guide about it. Its not really that hard.

Comment/Reply (w/o sign-up)

altin
hey
i have tryed this and the edit page contains few errors i think, i can't hoose toeditany images
the db isn't empty and i am contected with it ...

Comment/Reply (w/o sign-up)

biggiebi
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

What is wrong?

Comment/Reply (w/o sign-up)

Levis
QUOTE(Nqon @ May 30 2005, 11:06 AM) *

Im going through the tutorial today, is it posible for me to get some extra points for this. I mean, I wrote all those things in the code and you dont get points for that... sad.gif


Dude not everyone knows how to read PHP well. Really you should explain every line. A tutorial is something that explaines how something works, not just a bunch of code. I can read it but can average Bob read that. I know i can explain everything, buts its not my tutorial. If you wanna get more points from the admins, then maybe explain your tutorial, bit by bit.

Comment/Reply (w/o sign-up)

vujsa
QUOTE(biggiebi @ Nov 22 2006, 11:26 PM) *

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

What is wrong?

Yeah, don't do that again. When someone has an answer for you, they will reply. Don't post the same one line message over and over again. To begin with, the error message already tells you what to do! Assuming that you only have one field set for auto-increment, then go and set that as the table key!

If you have more than one field set for auto-increment, then unset the one that isn't correct.

Next time you want help with something, try to include some information with your request like an actual request.

vujsa

Comment/Reply (w/o sign-up)

Latest Entries

pyost
Could you copy the whole error?

Comment/Reply (w/o sign-up)

Team Destiny 07
Now I get a 1075 error every time I try to do this. Btw do the things for id and title and content appear auto-matically because I typed them in like you showed. Help?


~Zoroseerus a.k.a. Team Destiny07

Comment/Reply (w/o sign-up)

turbopowerdmaxsteel
QUOTE(Team Destiny 07 @ Mar 8 2007, 07:31 AM) *
Below I have an attached file and under the text create new database it says: No Privileges. What exatly does this mean? I am confused. I barely know the slightest amount of php (i'm not that good of a scriptor i'm not stupid either lol). Help?


You cannot Create or Delete the databases from within MYSQL because the default user does not have the appropriate privileges. Instead, use the Web Hosting Control Panel (Site Management Tools -> MYSQL Databases) to Create or Delete Databases.

Comment/Reply (w/o sign-up)

Team Destiny 07
Below I have an attached file and under the text create new database it says: No Privileges. What exatly does this mean? I am confused. I barely know the slightest amount of php (i'm not that good of a scriptor i'm not stupid either lol). Help?

Comment/Reply (w/o sign-up)

pyost
QUOTE
However, this doesn't seem like a very secure way to go about content management, as any old person could come along and edit or add pages.


And not only this. While the code is all fine, it is not secure enough. For example, if a host didn't have Magic Quotes on, inserting a text with apostrophes with in it would cause a MySQL error to occur. So, even if you are writing simple code (like this), it is highly recommended to sanitize user-entered data.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2
Similar Topics

Keywords : creating, content, managing, system, mysql

  1. How To: Display A Members/user List.
    With PHP, Mysql, and HTML. (4)
  2. Creating A Php Login Script
    A thorough look at the process behind it (3)
    Hey all, after reading through a fair number of tutorials on this subject I decided to write a
    pretty detailed one myself. Apologies for those who don't like my structured layout, it's
    just the way I do things. /wink.gif" style="vertical-align:middle" emoid=";)" border="0"
    alt="wink.gif" /> Title: Creating a PHP Login Script Objective: To go through a series of basic
    steps required to create a method of user registration, login and permission management using PHP
    and MySQL. Notes: The information is designed to work fully on AstaHost's hosting plans. ....
  3. Js/php/mysql Timer
    (2)
    In this tutorial I show a JS/PHP Timer. I use ingame password resetting as an example. I did borrow
    the JS from another online tutorial but the rest I did on my own. It works as its the source from my
    pass reset mostly. CODE if ($action == 'action1') // this is the action being
    performed, example: index2.php?page=passreset { // Process ID would go here. It has the user's
    id, and other things depending on the process. However because this is used to fetch the process
    from the DB it cannot have things like time or date as thy change on the next page. //c....
  4. Creating And Using Includes With PHP
    A simple tutorial (6)
    OK so you are now wanting to learn to use PHP and a few includes which are file(s) that you place
    into your script on any given page to indlude stuff that you have written previously. I did see
    another tutorial on such matters but possibly this tutorial will make more sense. PHP has the
    abilty to include other PHP files into the current script that is being processed by the server. Let
    us just take a simple example. This will be a file that will connect yo your database and a
    specified table. It will include all the necessary parameters to actually do just that. This....
  5. CMS102 - Content Management System Design
    Basic CMS With PHP & Flat File Databases (9)
    This topic is a follow up to CMS101 - Content Management System Design and PHP Tutorial: Menu Or
    Sidebar Script For CMS101 Overview: Now that we have discussed the basic concepts
    of a CMS written in PHP, we should begin to think about ways to make those concepts more useful and
    more powerful. Basically, using only what we have discussed so far, your website would still need a
    file for each and every page you wanted to display to your users. What we will discuss now a method
    of only creating one template file and a script that will automatically cha....
  6. CMS101 - Content Management System Design
    Basic CMS With PHP Includes (15)
    Overview: Frequently people ask about Content Management Systems here and are looking for
    advice regarding which CMS would work best for them. Often, the user requesting the help
    doesn't realize that they can design their own CMS that will provide them with the results they
    are looking for without needing to install a bulky program. This usually stems from the relatively
    few features that users want from their CMS. Many users just want an easy way to manage their
    website and edit their content. In this tutorial we'll discuss a very simple way to cr....
  7. How To Create A PHP Based Hit Counter
    With MySQL (2)
    websaint recently posted a PHP hit counter using a flat-file to store information. This is a guide
    a wrote a little while ago - it was for another web site, but I'll post it here as well.
    ----------------------------------------------------------------------------------- First and
    foremost, you need to create a new table. You can use a whole new database if you want (and assuming
    you have one free), but it's a bit of a waste. For this guide, our table will be called
    'hits', and will contain two fields - 'unique' and 'total'. The first ....

    1. Looking for creating, content, managing, system, mysql

See Also,

*SIMILAR VIDEOS*
Searching Video's for creating, content, managing, system, mysql
advertisement



Creating A Content Managing System - Using MySQL

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com