Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6369713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:50:24+00:00 2026-05-25T00:50:24+00:00

I’m tryin to insert dates using the date function while inserting posts. When the

  • 0

I’m tryin to insert dates using the date function while inserting posts.

When the form is submitted I get the following message:

Column count doesn't match value count at row 1

The SQL rows are in the correct order, the date row is the last one.

enter image description here

Here’s the function calling content:

function add_content($p){
    $title = mysql_real_escape_string($p['title']);
    $body = mysql_real_escape_string($p['body']);
    $p['time'] = date("F j, Y, g:i a");
    $time = $p['time'];

The rest of the code:

    <?php

class blog {
    private $host;
    private $username;
    private $password;
    private $db;
    private $link;

    public function __construct($host, $username, $password, $db){
        $this->db = $db;
        $this->link = mysql_connect($host, $username, $password, $db);
        mysql_select_db($this->db, $this->link) or die (mysql_error());
    }


    function get_content($id=''){
    if($id !=NULL):
        $id = mysql_real_escape_string($id);
        $sql = "SELECT * FROM content WHERE id = '$id'";
        $return = '<p><a href="index.php">Vover al Indice</a></p>';
    else:
        $sql = "SELECT * FROM content ORDER by id DESC";
    endif;

    $result = mysql_query($sql) or die (mysql_error());

    if(mysql_num_rows($result) !=NULL):
    while($row = mysql_fetch_assoc($result)){
        echo '<h1><a href="index.php?id='.$row['id'].'">'.$row['title'].'</a></h1>';
        echo '<span class="time">'.$row['time'].'</span>';
        echo '<p>'.$row['body'].'</p>';
        }
    else:
        echo '<p>Oops, post not found!</p>';
    endif;
    if(isset($return)){
        echo $return;
        }
    }

    function add_content($p){
        $title = mysql_real_escape_string($p['title']);
        $body = mysql_real_escape_string($p['body']);
        $p['time'] = date("F j, Y, g:i a");
        $time = $p['time'];

        if(!$title OR !$body):
            if(!$title):
                echo "<p>You have to fill the title.</p>";
            endif;
            if(!$body):
                echo "<p>You have to fill the body.</p>";
            endif;
            echo '<p><a href="add-content.php">Try again!</a></p>';
            else:
                $sql = "INSERT INTO content VALUES (null, '$title', '$body')";
                $result = mysql_query($sql) OR DIE (mysql_error());
                echo "Added sucessfully!";
            endif;

    }

    function manage_content()
    {
        echo '<div id="manage">';
        $sql = "SELECT * FROM content";
        $result = mysql_query($sql) or die(mysql_error());
        while($row = mysql_fetch_assoc($result)): ?>
            <div>
                <h2 class="title"><?php echo $row['title']?></h2>
                <span class="actions"><a href="update-content.php?id=<?php echo $row['id']?>">Edit</a> | <a href="?delete=<?php echo $row['id']?>">Delete</a></span>
        </div>  <?php
        endwhile;
        echo '</div>'; //End of Manage Div

    }

    function delete_content($id){
        if(!$id){
            return false;
        }else{
            $id = mysql_real_escape_string($id);
            $sql = "DELETE FROM content WHERE id = '$id'";
            $result = mysql_query($sql) or die (mysql_error());
            echo "Content Deleted Successfully";
        }
    }

    function update_content_form($id){
    $id = mysql_real_escape_string($id);
    $sql = "SELECT * FROM content WHERE id = '$id'";
    $result = mysql_query($sql) or die (mysql_error());
    $row = mysql_fetch_assoc($result);  ?>

     <form method="post" action="index.php">
        <input type="hidden" name="update" value="true"/>
        <input type="hidden" name="id" value="<?php echo $row['id']?>"/>
        <div>
            <label for="title">Title:</label>
            <input type="text" name="title"= id="title" value="<?php echo $row['title']?>"/>
        </div>
        <div>
            <label for="body"></label>
            <textarea name="body" id="body" rows="8" cols="40"><?php echo $row['body']?></textarea>
        </div>
        <input type="submit" name="submit" value="Update Content"/>

    </form><?php
    }

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

        if(!$title OR !$body):
            if(!$title):
                echo "<p>You have to fill the title.</p>";
            endif;
            if(!$body):
                echo "<p>You have to fill the body.</p>";
            endif;
            echo '<p><a href="update-content.php?id='.$id.'">Try again!</a></p>';
            else:
                $sql = "UPDATE content SET title='$title', body='$body' WHERE id = '$id'";
                $result = mysql_query($sql) OR DIE (mysql_error());
                echo "Updated sucessfully!";
            endif;
    }
}// End of Class
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:50:24+00:00Added an answer on May 25, 2026 at 12:50 am

    it should have 4 column, but this insert only set 3 columns

    INSERT INTO content VALUES (null, '$title', '$body')
    

    you are missing time column

    try

    INSERT INTO content VALUES (null, '{$title}', '{$body}', '{$time}');
    

    OR

    INSERT INTO content SET title='{$title}', body='{$body}', time='{$time}';
    

    second problem

    $p['time'] = date("F j, Y, g:i a");
    $time = $p['time']; // 25 characters long
    

    this exceed your column definition of varchar(20), the last 5 characters will get truncated

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.