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.

Recommended Answers

All 22 Replies

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

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

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

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

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 '<br>';
        echo '<ul>';
        for ($x=0; $x<sizeof($errorList); $x++)
        {
            echo "<li>$errorList[$x]";
        }
        echo '</ul></font>';
    }
}
?>
</body>
</html>

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

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

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)

Why don't use Smarty?

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

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.

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

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)

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

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

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.

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).

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

Is the source available?

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

Source will be available whenever I set up a site. I am in the progress of updating the entire backend, so alot of it won't work right until the new additions are added throughout the rest of it.

Cool, i have exams etc... right now but in about 1 month i aim to publish a beta of this forum engine that I am working on.

How did this story ended? It was very interesting though I was not there. I hope Benett is back from exams :)

I'm doing same CMS and would like to see this topic progressing!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.