Hey guys I cant seem to figure out what is going on with my cms I have started on making an admin panel and I have done it befroe and now I cant remake it to where it is working correctly? Can I get some help please?

this is my dashboard.php

<?php 
include '../_class/m3kheads_class.php';

$obj = new m3kheadsCMS();

//Setup connection vars
$obj->host = 'localhost';
$obj->username = 'root';
$obj->password = '';
$obj->db = 'cms';
//connect to db
$obj->connect();

?>
<?php
session_start();

if ($_SESSION['username'])
{

    echo"<pa>You are logged in as: ".$_SESSION['username'];
    echo "</pa>";

}
else
    header('location: index.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div class="wrapper">
<div class="header">
<img src="images/logo.png" id="logo"  />
</div>
<?php include 'lib/nav.php'; ?>
<?php 
    if($_POST['add']):
        $obj->add_content($_POST);
    endif;
?>
</body>
</html>

class

<?php 

    class m3kheadsCMS {
        var $host;
        var $username;
        var $password;
        var $db;

    function connect() {
        $con = mysql_connect($this->host, $this->username, $this->password)or die(mysql_error());   
        mysql_select_db($this->db, $con)or die(mysql_error());

    }// Ends Connect

    function get_content(){
        $sql = "SELECT * FROM content ORDER BY id DESC";
        $res = mysql_query($sql)or die(mysql_error());
        while($row = mysql_fetch_assoc($res))   {
            echo '<h1>' . $row['title'] . '</h1>';
            echo '<h3>Author: ' . $row['author'] . '</h3>';
            echo '<p>' . $row['body'] . '</p>';
        }

    }//ends get_content

    function add_content($p) {
        $title = mysql_real_escape_string($p['title']);
        $body = mysql_real_escape_string($p['body']);

        if(!$title || !$body):

            if(!$title):
                echo "<p>The title is required!!</p>";
            endif;
            if(!$body):
                echo "<p>The body is required!!</p>";
            endif;

            echo '<p><a href="add_content.php">Try again?</a></p>';
            else:
                $sql = "INSERT INTO content VALUES (null, '$title', '$body')";
                $res = mysql_query($sql) or die(mysql_error());
                echo "Added Successfuly";
            endif;
    }// Ends add_content

}// Ends Class
?>

after i try and add it says

Column count doesn't match value count at row 1

Recommended Answers

All 5 Replies

Member Avatar for Zagga

It may be because you are inserting data without specifying which fields the data relates to. For example, I am guessing the value 'null' is being inserted into the 'id' field instead of the 'author' field.

Try change your SQL (line 41) to this:

$sql = "INSERT INTO content (author, title, body) VALUES (null, '$title', '$body')";

Looks like you're missing the author and possibly other values from your insert query.

Either explicitly list each field you intend to provide a value for or ensure you provide a value for all fields.

Member Avatar for Zagga

Could you post your table structure please?

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.