July 21st, 2008
Tutorial : Creating a Content Management System using PHP/MySQL
Its been 2 weeks since visionmasterdesigns.com was started and I am very glad with the response. Lot of people want to explore PHP/MySQL more and I think I`ll give in to that
. So Today lets design a Content Management System using PHP/MySQL.
Index
- Page 1 : Introduction
- Page 2 : Database Work
- Page 3 : functions.php
- Page 4 : articlefunctions.php
- Page 5 : insertarticle.php
- Page 6 : editarticle.php
- Page 7 : article.php – Our start File
- Demo – Here
- Script – Here
Don`t get scared seeing the number of pages. This system has 5 files as listed above. Our CMS features add,edit and delete article records.
Introduction to CMS
CMS is an application through which you can add content without the need of uploading any files. You can create,edit,delete articles directly online. These articles are stored in the backend i.e database, in our case MySQL. Everytime user requests for a particular article, the php script retrieves the article and displays it to the user.
I`ll try to keep it as simple as possible.















December 29, 2009 at 3:39 pm
Theres no database structure for this tutorial. Can anybody provide a it please.
Does anybody have an updated version for this with complete layout that gives you the ability to make pages visible or hide without deleteing pages/articles. also allow you to move the position up and down.
December 28, 2009 at 6:55 am
In some cases, phpadmin does not have password for "root". In that case, its suffice to omit 'admin' from function.php line 5 and do away without password, so your script should look like this :
function connect() {$conn = mysql_connect('localhost', 'root');
If not, you'll receive connecting error.
December 27, 2009 at 2:52 pm
bro, i can't access or view the demo file. Please tell me what am i suppose to do to get it right. Cheers for now.
November 10, 2009 at 7:39 am
Hello,
i'm a newbie and found this very nice but I feel it's not one for the newbies, this is designed at programmers who have experience of writing php and mysql, who don't really need the tutorial as they hav experience of it already.
What I feel it lacks is their is no use of CSS or any explanation of how to incorpotare CSS into the design, how would anyone upload pictures and place them where needed?
How to make content bold, centered, left or right. or use any other features.
I would be very grateful if you have a working CSS based CMS example that you can forward to me at kaise@hotmail.co.uk.
Kind Regards
kaise
December 28, 2009 at 7:00 am
Kaise, you can have your css file created separately and call it in your "article.php" file. Its just like how your set layouts in html, same rules apply. its common sense, mate.
October 29, 2009 at 9:34 am
I get this error:
Warning: Cannot modify header information – headers already sent by (output started at /home/——/public_html/main/articlefunctions.php:12) in /home/——-/public_html/main/articlefunctions.php on line 44
y?
October 19, 2009 at 1:57 pm
Hi any one knows how to add a subpage on each page created? If someone knows please help me. Need it asap.
September 6, 2009 at 9:32 am
Nice Tutorial. So much thanks for you.It’s simple to understand !
May I ask,how can I create a PHP that can upload image in the article? Would you have the related tutorial?
I search thousand of these kind of tutorial..and I only can get a successful start in your post.Thank you so much!
July 17, 2009 at 7:08 pm
Hi i really need help i have a project and its due next week, If a article does not exist how can i make an error saying this page does not exsit e.g. article.php?id=55 (ID:55 does not exsist) and it deisplays “This article could not be found” how can i do that??
This is due next week please help!!!
July 18, 2009 at 4:33 am
Do you have access to your mysql database? In there you will see the article table and the ID number that should apply to the heading of the article you are working on. Place that ID number in the php code of the page that contains the article.
July 17, 2009 at 2:14 am
How can i add an error if “?id=” nothing all i get is an empty page
Help Me!
August 21, 2009 at 6:49 pm
You can write an if statement to target the setting for 1 and if it doesn’t exist. If the if statement returns true, then you have one file in the system and it displays. If it is false, then, you simply echo a statement of ” There are no current articles “.
Here is a very simple example:
if (!’id’== 1 ) {
echo ” There is no current…” ;
}
else (‘id’== 1) {
return ‘id’;
}
August 21, 2009 at 6:56 pm
Quick note, the setup I gave you there was going from the id of the article itself, not the user id that can be easily confused by the way I wrote that.
Create your variable and value to reflect the article and don’t expose your actual ” ID ” to the public return that this example calls on.
Example variable and value to use:
$article_id = ‘ article_id ‘ ;
Use that and replace the ‘ id ‘ with ‘ article_id ‘ for using this example. I would hate to have my first post trash a bunch of novice code by having them give up the ghost…heh. Just FYI- change the id labels.
August 23, 2009 at 10:42 am
Brad – thanks for the information. Are you suggesting that the tables in the database be amended from ID to article_id? Another matter – do you have a script that will allow for an image to be loaded to a html page from a mysql database. I am looking to update the html page with article information as well as an image.
August 25, 2009 at 9:31 pm
Hey Ken,
Yeah, for my example only though…replace the ‘ id in the example to ‘ article_id ‘ to protect your files and not cross it with a user_id, which is normally referenced by the standard ‘ id ‘ label.
As for the second part, here is a really good reference tutorial on how to do just what you are looking for. It is primarily uploading images to a db but, it tells you how to display them back as well.
If you need anymore help with it, let me know and I’ll do my best to see what we can do about it.
August 25, 2009 at 9:32 pm
Here’s the tutorial link:
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx
July 10, 2009 at 7:40 am
Sorry, JS gets slashed on here. You know what I meant.
June 24, 2009 at 1:20 am
Hello, Thanks for the tut but i managed to create sub pages aswell but the only problem is i want it to look like this
index.php?p=Home&subpage=Hi
but it looks like this index.php?p=Home then to view sub page you go on sub.php?subpage=Hi, Do you have any files on sub pages (ive just added sub pages e.g. colum = Sub = Home).
Thank You
August 21, 2009 at 7:25 pm
I ‘ think ‘ I understand what yo uare asking here…Try handling your subpages by checking out the articlefunctions.php of this article series and refubish the connection code to replace the current $action variable with $subpages, remove the sql processing and use the header location to point your proper pages for display. It will work the same way for what you are wanting to do. Also, look into ‘ object-oriented programming ‘ for more detailed methods on achieving this same result in a LOT better fashion.
October 19, 2009 at 2:49 pm
Hi dave can you teach me how to add subpage? i need your help. Thanks a lot.
May 29, 2009 at 11:02 am
great tutorial for beginner, but when i visit the page demo i got some error when insering data. like this
Warning: Cannot modify header information – headers already sent by (output started at /home/visionma/public_html/demo/cms/articlefunctions.php:12) in /home/visionma/public_html/demo/cms/articlefunctions.php on line 32
if im not wrong, perhaps you place the header(“Location:page.php”); after your html page, or in switch control logic…:-(, your page tutorial also get and error when request it, may be something wrong in your server. I think u need to repaired it,
it is very awesome!….i just take the script..
but…you have done the good stuff
thank you
May 31, 2009 at 12:37 am
Thanks a lot for noticing the error. I`ll definately work a fix on it
June 26, 2009 at 11:26 am
I am still getting this message after I add a new article title – Warning: Cannot modify header information – headers already sent by (output started at /home/ricniven/public_html/kenbirddesigns/bowlingclub/cms/articlefunctions.php:12) in /home/ricniven/public_html/kenbirddesigns/bowlingclub/cms/articlefunctions.php on line 32.
August 25, 2009 at 9:38 pm
Ken, it is probably clashing headers. Try putting ‘ exit( ) ; ‘ after the ‘ header(“Location: article.php”); ‘ lines to break that up. It’s recycling because a header function doesn’t ‘ disolve ‘ or time out without an exit function to kill it.
May 27, 2009 at 1:14 am
THANK YOU!!!!
I needed this script!
May 25, 2009 at 11:58 pm
Cara, onde tá o começo do script?? oras, como podem estar elogiando. O script não tem nem começo. A página deve estar interpretando o código oras. Vamos fazer um coisa bonita vai gente. Vamos fazer algo legal. A intenção é ótima, mas, se não pode ser utilizada, do que adianta.
Valeu.
Desculpe a sinceridade.
Carlos.
May 23, 2009 at 2:36 pm
Very good tuto !
____________________
Saguenay-IT, (IT Outsourcing, SOA, PHP, ASP, Flex, ActionScript, JavaScript…)
April 26, 2009 at 5:02 pm
nice article
April 16, 2009 at 10:35 pm
hey,
i am new starter well, i am trying out the tutorial .plz help out with following error
PHP Parse error: parse error in C:\Server\www\myserver.dev\public_html\functions.php on line 11
February 5, 2009 at 9:14 am
found the source code and so my question is moot. Thanks anyway. Still having a problem getting it to work but I’m working on it.
February 4, 2009 at 7:29 am
in this tutorial I think I am missing part of the code. I see the end of php statement but not the start. Here is what I get on the website:
‘.$row['articleTitle'].’ – EDIT – DELETE’;
}
}
closeconnection($conn);
}
function getArticle($id) {
$conn = connect();
$sql = “SELECT * FROM article WHERE id=’$id’”;
$result = mysql_query($sql);
if($result) {
$row = mysql_fetch_assoc($result);
$articleinfo[] = $row;
}
return $articleinfo;
closeconnection($conn);
}
?>
Is this correct? Am I missing something? Any help? Thanks
June 26, 2009 at 12:53 am
i have the same problem here. but there is some code missing.
it is the part how to connect to the db table.
January 27, 2009 at 1:12 am
Hey,
This comment is simply to help anyone who directly used the source code.
You will recieve a PHP Notice stating that the ID is not defined, when the article.php page is loaded. To ignore this Notice and remove it from displaying in your browser, simply place an @ sign at the problem line.
It should look like this:
@$id=$_GET['id'];
This will remove the Notice so your page displays as intended.
I hope this helps.
Regards,
Dan
November 16, 2008 at 7:29 pm
Michael,
I dont see a reply to AndrewPoison’s question…. It’s this article. You have seven pages in this article. How do you do that without a plugin, then?
COuld you please help us on that? I would like to use the same without any plugin. Just pure php code.
October 7, 2008 at 9:01 pm
I get a 404 error when I try to run the demo on my machine. All of the code is in “public_html” and I even created a sub folder called “cms” and download the code from the site there and I still get Http (404). Any ideas?
September 17, 2008 at 1:59 am
I’m having the same problem as Nico. Turning on error reporting gives me:
Notice: Undefined index: id in C:\server\www\myserver.dev\public_html\admin\articlefunctions.php on line 15
Any thoughts would be greatly appreciated!
August 16, 2008 at 9:00 pm
glad the problem is solved. Thanks AndrewPoison
August 15, 2008 at 11:46 pm
Hi Andrew
Thanks for the reply. I just checked the Go button “action statement” and it is correct. In my message above I was talking about the “url” shown in the “address bar” in the browser. I have kept the directory stucture the same.
umm… I think that the bug is in the communication between the php and the mySQL database. If that helps in any way.
August 15, 2008 at 9:57 pm
/edit: if you did, try a single point or even no point at all (“./articlefunctions.php?a=add” or “/articlefunctions.php?a=add”) instead.
August 15, 2008 at 9:55 pm
@Nico: isnt it supposed to be
action=”articlefunctions.php?a=add”
and not
action=”../articlefunctions.php?a=add” ? Or did you change the directory structure?
August 15, 2008 at 9:14 pm
Hi Michael!
This is my first attempt at PHP and MySQL so please bear with me.
OK so it all works, until I fill in the details (../insertarticle.php) try to click the button “Go”. Then I get a blank white screen and the link is pointing to ../articlefunctions.php?a=add.
I guess I am doing something wrong here and I guess “Help Please!” is the next question
August 13, 2008 at 10:03 pm
It’s this article. You have seven pages in this article. How do you do that without a plugin, then?
I am using WP 2.6 and don’t see any way how to get this working :/
Btw: would it be okay for you if I translate some of your articles into german and post them on my site (with a link back to you, of course)? I found them to be quiet usefull and would like to present them another audience.
August 13, 2008 at 7:43 pm
Hello Andrew,
I haven`t used any plugin to have multiple pages in an article. Which page are you talking about ?
August 12, 2008 at 7:01 pm
Hey there, Michael,
what’s the name of the plugin you used to have multiple pages in one single article?
August 1, 2008 at 12:47 pm
Hi Michael,
If this is only a warning…. How do we go about to give you rather an example of what the article looks like after its been updated or edited..
July 26, 2008 at 1:58 pm
hey mightygame,
its not an error, just a warning,
header() function is used when you want to redirect to a particular page or tell the browser what content your page is of.
Don`t worry, its not an error as long as the system is working.
Regards
July 26, 2008 at 6:10 am
I get this error:
Warning: Cannot modify header information – headers already sent by (output started at /home/——/public_html/main/articlefunctions.php:12) in /home/——-/public_html/main/articlefunctions.php on line 44
y?
July 10, 2009 at 7:39 am
Replace the header(); function with this:
echo “window.location = ‘article.php’;”;