954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

New CMS - Help Needed

Ok i am making a CMS using PHP/Mysql (its designed as a learning experience for me so it will not be anything like mambo etc... :) )

Anyway, here are some screenies. If anyone wants to help then I would happily share what little code I have written.

Attachments add.JPG 45.98KB id.JPG 67.38KB main.JPG 41.42KB
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Looks like a good start. No better way of learning than diving in and trying to actually build something useful!

pty
Posting Pro
530 posts since Oct 2005
Reputation Points: 64
Solved Threads: 39
 

hmm i am going to try and add a search function and an admin panel

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

hey heres a little function i used in order to make PHP's date/time more human readable.

<?php
function formatDate($val)
{
    $arr = explode('-', $val);
    return date('d M Y', mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
}
?>


someone may find it useful

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Aha! Ok i made the admin panel. The admin can now add/edit/delete

now i just need some sort of authentication and a search function

Attachments add.jpg 41.06KB admin.JPG 36.97KB edit.jpg 58.62KB index.JPG 30.12KB story.JPG 77.15KB
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

why is this code not working:

(its meant to edit - i always get error on the last line?)

<html>
<body>
<table width="100%" cellspacing="0" cellpadding="5">
<tr>
    <td bgcolor="Orange"><font size="5" color="Black">
    <b>James Bennet's CMS</b></font>
    </td>
</tr>
</table>
<?php
include('../lib/conf.php');
include('../lib/functions.php');
if (!$_POST['submit'])
{
     if ((!isset($_GET['id']) || trim($_GET['id']) == '')) 
     { 
         die('Missing record ID!'); 
     }
    $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to mysql database!');
    mysql_select_db($db) or die ('Unable to select mysql database!');
    $id = $_GET['id'];
    $query = "SELECT title, content, contact FROM news WHERE id = '$id'";
    $result = mysql_query($query) or die ("Error in mysql query: $query. " . mysql_error());
    
    if (mysql_num_rows($result) > 0)
    {
        $row = mysql_fetch_object($result);
?>
<table cellspacing="5" cellpadding="5">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="id"  value="<?php echo $id; ?>">
<tr>
    <td valign="top"><b><font size="2">Title</font></b></td>
    <td>
      <input size="50" maxlength="250" type="text" name="title" 
value="<?php echo $row->title; ?>">
    </td>
</tr>
<tr>
    <td valign="top"><b><font size="2">Content</font></b></td>
    <td>
      <textarea name="content" cols="40" rows="10">
      <?php echo $row->content; ?>
      </textarea>
    </td>
</tr>
<tr>
    <td valign="top"><b><font size="2">Contact Address:</font></b></td>
    <td>
      <input size="50" maxlength="250" type="text" name="contact"
      value="<?php echo $row->contact; ?>">
    </td>
</tr>
<tr>
    <td>
        <input type="Submit" name="submit" value="Edit">
</td>
</tr>
</form>
</table>
<?php
    }
    else
    {
        echo '<font size=-1>That content could not be located in our database.</font>';
    }
}
else
{
    $errorList = array();
    
    $title = $_POST['title'];
    $content = $_POST['content'];
    $contact = $_POST['contact'];
    $id = $_POST['id'];
        
    if ((!isset($_POST['id']) || trim($_POST['id']) == '')) 
    { 
      die ('Missing record ID!'); 
    }
    if (trim($_POST['title']) == '') 
    { 
      $errorList[] = 'Invalid entry: Title'; 
    }
    
    if (trim($_POST['content']) == '') 
    { 
      $errorList[] = "Invalid entry: Content"; 
    }
    
    if (trim($_POST['contact']) == '') 
    { 
      $contact = $def_contact; 
    }
    
    if (sizeof($errorList) == 0)
    {
        $connection = mysql_connect($host, $user, $pass) or die ('Unable to connect to mysql database!');
        mysql_select_db($db) or die ('Unable to select mysql database!');
        $query = "UPDATE news SET title = '$title', content = '$content', contact = '$contact', timestamp = NOW() WHERE id = '$id'";
        $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
        echo '<font size=-1>Update successful!';
        echo '<a href=index.php>Go back to the main menu</a>.</font>';
        mysql_close($connection);
    }
    else
    {
        echo '<font size=-1>The following errors were encountered:'; 
        echo '';
        echo '<ul>';
        for ($x=0; $x<sizeof($errorList); $x++)
        {
            echo "<li>$errorList[$x]";
        }
        echo '</ul></font>';
    }
}
?>
</body>
</html>
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

You probs missed a { or } or ( or ) somewhere
otherwise that is my knowledge wasted!

Serunson
Posting Maven
2,578 posts since Mar 2007
Reputation Points: 533
Solved Threads: 46
 

== '') ==> that dont look right ~
should it not be like =="") ?

Serunson
Posting Maven
2,578 posts since Mar 2007
Reputation Points: 533
Solved Threads: 46
 

here are screenshots of the newest version . I got .htaccess authentication running. Full code is here and if possible can get some help making it look nicer.

Source code included (not the htaccess stuff)

Attachments add.JPG 41.95KB admin.JPG 59.55KB article.JPG 92.76KB cp.JPG 43.81KB edit.JPG 59.61KB main.JPG 41.47KB index.zip (5.65KB)
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Why don't use Smarty?

didier-fr
Junior Poster
143 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

Because i want to learn how to use php/mysql myself properley. I find that starting out with a big, real life project is a good way to begin programming a new language.

Ive changed it a bit now. You can now comment on news and login

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

I'm in the process of constructing an application for my work.

If you get Hamachi and log on to my network you can take a look.

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 

Here is the newest version in zip. The sql statement to make the CMS tables is under /admin and the sql table for the adressbook can be run via a hyperlink

Attachments index.zip (8.85KB)
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Ok things have progressed over the last month. I have migrated the CMS to a new model of CSS and Includes so that it can be easialy modified for the end user (the table and db names are no longer hard-coded etc...)

The admin panel has also bee greatly improved and working .Htaccess security has been added

Ive changed a lto of the code to make it faster and less vulnerable to SQL Injection atatcks.

to install:

create a database
fill out conf.php with the username/password as well as the database and table name

there is a SQL statement to create the table under /admin/misc. (Change the table name for whatever you specified in the conf file)

The username/password for .htaccess is root and v3nusian. Use a .htpassword generator to change it to whatever you want.

Screenhots (code coming soon)

Attachments 1.png 38.43KB 2.png 106.23KB 3.png 79.78KB 4.png 17.73KB 5.png 16.03KB
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

hey this great do you know i was trying to do the same as your code with some diffrence from it i need to add stories and image cms for adv magazine so i study your code it is nice i have studing php and mysql for three days now and trying to read codes as i can i found your code is easy and learn alot from it thanks very much to share it with us

samoual
Newbie Poster
6 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

This CMS is based one one from the book "how to do everything with php and mysql" by Vikram Vaswami. You can get it on amazon for like $30. You should get it, it teaches you in a very easy way. Its designed for people new to php and mysql but who have some (basic) html experience

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

Hey, Samoual. Here is the newest version if you want to look at it. There is a readme (README!.TXT) which explains how to set up the database and stuff. This version is very easy to set up.

Attachments cms.zip (9.29KB)
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

I started mine from the same code, and the editing news didn't work either without re-adjusting it :P Its a great starting point though, hope you actually locked the admin down with the htaccess too, else that system is open to any attack.

I've been working on it for about a year now, and its came well beyond what it started as (screens below). I have since added my own user system (my personal edition integrated to the VBulletin user base), added a download manager and some other neat things.

Ive set it up somewhat similar to Joomla, since that was what I found to be one of the easiest (though its extremely bloated) CMS'. I havent done any template system yet, but plan to get to that here shortly. If I can even finish it up, I plan to release it Open Source and offer a larger commercial support system (regular support through forums).

Attachments cms1.jpg 255.38KB cms2.jpg 294.76KB
xKillswitchx
Newbie Poster
2 posts since Jan 2007
Reputation Points: 10
Solved Threads: 0
 

is this a simple code to learn CMS? Html was fairly difficult at first but got easier.

Serunson
Posting Maven
2,578 posts since Mar 2007
Reputation Points: 533
Solved Threads: 46
 

Is the source available?

Ive made a new (open source) version since then (included)

Attachments jbcms_0point2.zip (22.2KB)
jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You