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

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


if ($_SESSION['username'])

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

    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">
<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>

<div class="wrapper">
<div class="header">
<img src="images/logo.png" id="logo"  />
<?php include 'lib/nav.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):

                echo "<p>The title is required!!</p>";
                echo "<p>The body is required!!</p>";

            echo '<p><a href="add_content.php">Try again?</a></p>';
                $sql = "INSERT INTO content VALUES (null, '$title', '$body')";
                $res = mysql_query($sql) or die(mysql_error());
                echo "Added Successfuly";
    }// 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

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

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, learning, and sharing knowledge.