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 id.JPG 67.38 KB main.JPG 41.42 KB

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

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

Attachments add.jpg 41.06 KB admin.JPG 36.97 KB index.JPG 30.12 KB story.JPG 77.15 KB

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>

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)

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)

Attachments 1.png 38.43 KB 2.png 106.23 KB 3.png 79.78 KB 4.png 17.73 KB 5.png 16.03 KB

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.

Attachments

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.38 KB cms2.jpg 294.76 KB

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!

This article has been dead for over six months. Start a new discussion instead.